I want to add a hotkey by script. The regular Addon tutorial mentions how to add a normal hotkey. But i need a Map Type Mouse, left mouse button, with holding down a modifier key. And i run into trouble here.

My current code is

kmi = km.keymap_items.new("view3d.paint_select", map_type = 'MOUSE', type = 'LEFTMOUSE', value = 'PRESS', key_modifier = 'I')

And i get this error:

TypeError: KeyMapItems.new(): was called with invalid keyword argument(s) (map_type), expected (idname, type, value, any, shift, ctrl, alt, oskey, key_modifier, head)

map_type is missing in the expected list of keywords. But where else should i put it then? Is map_type not part of KeyMapItem?


Shift+LMB example to toggle Properties > Scene > Simplify:

import bpy

# operator
class ToggleSimplify(bpy.types.Operator):
    bl_idname = "view3d.toggle_simplify"
    bl_label = "Toggle Simplify"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        context.scene.render.use_simplify = not context.scene.render.use_simplify
        return {'FINISHED'}

addon_keymaps = []
# register
def register():

    # handle the keymap
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(ToggleSimplify.bl_idname, type='LEFTMOUSE', value='PRESS', shift=True)
        addon_keymaps.append((km, kmi))

# unregister
def unregister():

    for km, kmi in addon_keymaps:


if __name__ == "__main__":

Also see: https://www.blender.org/api/blender_python_api_current/bpy.types.KeyMapItems.html

  • $\begingroup$ Thank you, you were both right. It's enough to use type='LEFTMOUSE' . That's what i was searching for :) $\endgroup$
    – Tiles
    Aug 3 '16 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.