# 2.8 Shortcut to turn on/off "Emulate 3 Button Mouse"..?

Could use some insight please, I am not sure how to properly formulate this question (brand new to 3D and Blender 2.8). After reading up on various forums there maybe a way to reprogram a keymap shortcut for the ALT key?

I prefer having the "emulate 3 Button Mouse" checked for general tumbling/navigation so I don't have to use the MMB when zooming or nudging viewport but when "emulate 3 Button Mouse" is checked it nukes the ability to employ the ALT key for selecting edge loops/rings.

I found that Left Double Click works although selection is limited and does not do half of what is available as far as selecting/deselecting goes... Hmmm?

Sorry for long scenario here, not sure if there is a workaround. It's be nice though.

Thanks in advance. :)

• I wanted this as I find using the MMB to be a bit of a strain compared to the other buttons, I agree it is easier to use the ALT key for rotating the camera. Feb 28 at 12:00

Blender's keymap requires an operator to execute when the shortcut is pressed. Currently there is no operator to toggle the Emulate 3 Button Mouse option from the preferences, but this can be solved by writing a little add-on.

The following add-on creates an operator that allows to toggle the preference option and can therefore be added as a shortcut into your keymap. Copy & paste the script into a file and save it with the .py file extension.

bl_info = {
"name": "Toggle 'Emulate 3 Button Mouse'",
"author": "Robert Guetzkow",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "Edit > Operator Search",
"description": "Operator for toggeling the 'Emulate 3 Button Mouse' option.",
"warning": "",
"wiki_url": "",
"category": "Preferences"}

import bpy

class PREFERENCES_OT_toggle_emulate_3_button_mouse(bpy.types.Operator):
bl_idname = "preferences.toggle_emulate_3_button_mouse"
bl_label = "Toggle 'Emulate 3 Button Mouse'"

def execute(self, context):
context.preferences.inputs.use_mouse_emulate_3_button = not context.preferences.inputs.use_mouse_emulate_3_button
return {"FINISHED"}

classes = (PREFERENCES_OT_toggle_emulate_3_button_mouse,)

def register():
for cls in classes:
bpy.utils.register_class(cls)

def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)

if __name__ == "__main__":
register()


You can install the add-on in Edit > Preferences > Add-ons.

Once it's installed you will have to enable it. You can find it in the Preferences category.

Then switch to the Keymap in the preferences and add a shortcut referencing the operator from the add-on. You'll have to decide what key binding you'd like to use.

• wow thank you, this is way above my level of expertise but I will try my best. I am only guessing but do I save the script as a .py or is there a file extension blender prefers ? Oct 15 '19 at 15:12
• Yes, you need to copy & paste the code into a file and save it with .py extension, for example toggle_emulate_3_mouse_button.py. In the preferences in the Add-ons section there is an Install button at the top. Click it and select the file. Oct 15 '19 at 15:17
• It should show up in the list of add-ons afterwards. You need to enable it by clicking on the checkbox next to it. Oct 15 '19 at 15:18
• I did it..! You Sir are a genius! Thank you so much. It took a bunch of attempts but made it work. Oct 15 '19 at 16:05
• @halipino You're welcome! If my answer solved your problem, please mark it as accepted by clicking on the checkmark. Oct 15 '19 at 16:08

Building on Robert Gützkow's excellent answer and script, I've updated the script to perform a similar task for Emulate Numpad, and which also applies the hotkeys for your particular concern (Toggling Emulate Middle Mouse Button) that involved an extra manual step in Robert's Answer:

" for Toggle Emulate Middle Mouse Button

; for Toggle Emulate Numpad

You may change these hotkeys in the Preferences.

bl_info = {
"name": "Toggle 'Emulate 3 Button Mouse' & 'Emulate Numpad'",
"author": "brybalicious courtesy Robert Guetzkow",
"version": (1, 0),
"blender": (2, 90, 1),
"location": "Edit > Operator Search",
"description": "Operator for toggling the 'Emulate 3 Button Mouse' & 'Emulate Numpad' options",
"warning": "",
"category": "Preferences"}

import bpy
import rna_keymap_ui
from bpy.utils import register_class, unregister_class

# Surfacing the Operators
# They can now be looked up via their bl_label attribute with the search function on default hotkey F3

class PREFERENCES_OT_toggle_emulate_3_button_mouse(bpy.types.Operator):
bl_idname = "preferences.toggle_emulate_3_button_mouse"
bl_label = "Toggle 'Emulate 3 Button Mouse'"

def execute(self, context):
context.preferences.inputs.use_mouse_emulate_3_button = not context.preferences.inputs.use_mouse_emulate_3_button
return {"FINISHED"}

bl_label = "Toggle 'Emulate Numpad'"

def execute(self, context):
return {"FINISHED"}

# Keymap Code

# First, set up a dictionary of key mappings.

# "TEMPLATE": [{"label": "Human readable name of keymap in Blender Keymap UI",
#               "region_type": "WINDOW", //Default is WINDOW (optional)
#               "space_type", "EMPTY", //Default is EMPTY
#               "map_type": "KEYBOARD", //Device to be used (optional)
#               "keymap": "Window", //Name to be chosen from declared list of keymap names
#               "idname": ..., //Specific reference to operator from blender API
#               "type": "", //Key type identifier - choose a specific keyboard button or mouse button, etc...
#               "ctrl": False, //Combination keys for compound hotkeys (optional)
#               ...
#               "value": "PRESS"}, //Whether key will be held, pressed, etc...
#              {...}]

keys = {"MENU": [{"label": "Toggle Emulate 3 Button Mouse",
"region_type": "WINDOW",
"space_type": "EMPTY",
"map_type": "KEYBOARD",
"keymap": "Window",
"idname": "preferences.toggle_emulate_3_button_mouse",
"type": "QUOTE",
"ctrl": False,
"alt": False,
"shift": False,
"oskey": False,
"value": "PRESS"
},
{"label": "Toggle Emulate Numpad",
"region_type": "WINDOW",
"space_type": "EMPTY",
"map_type": "KEYBOARD",
"keymap": "Window",
"type": "SEMI_COLON",
"ctrl": False,
"alt": False,
"shift": False,
"oskey": False,
"value": "PRESS"
}]}

# Define a function to get a list of key mappings, 'keylists'
def get_keys():
keylists = []
return keylists

# Define a function to register the key mappings templated in the dict as keymaps, using the constructor kc.keymaps.new()
def register_keymaps(keylists):
wm = bpy.context.window_manager

keymaps = []

for keylist in keylists:
for item in keylist:
keymap = item.get("keymap")
space_type = item.get("space_type", "EMPTY")
region_type = item.get("region_type", "WINDOW")

if keymap:
km = kc.keymaps.new(name=keymap, space_type=space_type, region_type=region_type)
# km = kc.keymaps.new(name=keymap, space_type=space_type)

if km:
idname = item.get("idname")
type = item.get("type")
value = item.get("value")

shift = item.get("shift", False)
ctrl = item.get("ctrl", False)
alt = item.get("alt", False)
oskey = item.get("oskey", False)

kmi = km.keymap_items.new(idname, type, value, shift=shift, ctrl=ctrl, alt=alt, oskey=oskey)

if kmi:
properties = item.get("properties")

if properties:
for name, value in properties:
setattr(kmi.properties, name, value)

keymaps.append((km, kmi))
return keymaps

# Define a function to unregister the keymaps
def unregister_keymaps(keymaps):
for km, kmi in keymaps:
km.keymap_items.remove(kmi)

classes = (PREFERENCES_OT_toggle_emulate_3_button_mouse, PREFERENCES_OT_toggle_emulate_numpad)

def register():
for cls in classes:
register_class(cls)

global keymaps
keys = get_keys()
keymaps = register_keymaps(keys)

def unregister():
global keymaps
for km, kmi in keymaps:
km.keymap_items.remove(kmi)

for cls in classes:
unregister_class(cls)

# if __name__ == "__main__":
#     register()


To install, please download or clone the repository from https://github.com/brybalicious/toggle_mmb_numpad.git and follow the same instructions for installing the addon as an archive with .zip extension, as per Robert's answer. Hope this helps!

• Ineresting, but please prefer past the code here instead of refering an external link. Thanks you. Nov 2 '20 at 13:12
• sure thing @lemon I updated with the code inline. If the answer is satisfactory now, please rate it :) Nov 3 '20 at 10:36
• I like this automates adding the keymap, I did find that using the double quote didn't work right. It seems you cannot use any key in preferences > Keymap that requires you to hold down the shift key first for a symbol, it only picks up left shift or right shift. It works to set in code but I could not reliably get the shortcut key to work. Feb 28 at 11:58
• It's a few more keys but I used Ctrl+Alt+Shift+Q. Blender does have quite a few functions, single letter shortcut keys are probably all used already :). Feb 28 at 11:58