You can assign different hotkeys to one operator.
But when it is executed, how can it be determined with which hotkey it was called?
import bpy
class MyOperator(bpy.types.Operator):
bl_idname = "node.my_op"
bl_label = "My Operator"
myProp: bpy.props.StringProperty(name="Aaa", default="1")
def execute(self, context):
kmUser = bpy.context.window_manager.keyconfigs.user.keymaps['Node Editor']
#next: ???
print("Hi, you called this operator using `type=idk`, `shift=idk` and `alt=idk`")
#print(kmUser.keymap_items['node.my_op'], self.myProp)
return {'FINISHED'}
def register():
bpy.utils.register_class(MyOperator)
km = bpy.context.window_manager.keyconfigs.addon.keymaps.new(name="Node Editor", space_type='NODE_EDITOR')
km.keymap_items.new(idname=MyOperator.bl_idname, type='H', value='PRESS', shift=True)
kmi = km.keymap_items.new(idname=MyOperator.bl_idname, type='D', value='PRESS', alt=True)
kmi.properties.myProp = "2"
if __name__=="__main__":
register()