Script by Robert Guetzkow
Download the emulate.py file and install it as you would normally install an add-on, and enable it.
After installation, go to Preferences > Keymap > Window, and Add New at the bottom. Expand the new keybind and paste the following as the value of identifier:
preferences.toggle_emulate_3_button_mouse
Set the keybind to anything you want.