I have a custom panel in which I have buttons that can use modifier keys, IE Clicking, Ctrl+Clicking, Alt+Clicking etc all do slightly different things and it works as expected. I want to hotkey the UI button but dont know how to differentiate if its called via the UI (and take modifiers into account) or via a hotkey (and not take the modifiers into account).
class dummyButton(bpy.types.Operator):
bl_idname = "view3d.fd_dummybutton"
bl_label = "Dummy Button"
bl_options = {'REGISTER', 'UNDO'}
modeEnum : bpy.props.EnumProperty(
items = {
("1", "Stuff", ""),
("2", "Other stuff", ""),
("3", "Even more stuff", ""),
("4", "Final stuff", "")
},
name = "Mode",
default = "1"
)
def invoke(self, context, event):
if event.ctrl:
self.modeEnum = "2"
elif event.shift:
self.modeEnum = "3"
elif event.alt:
self.modeEnum = "4"
return self.execute(context)
def execute(self, context):
if self.modeEnum == "1":
print("Do stuff")
elif self.modeEnum == "2":
print("Do other stuff")
else:
print("Stuff")
return {'FINISHED'}
I'd prefer to use an enum since then I can choose the function in the hotkey menu
I want to be able to use Ctrl+9 as a hotkey without it forcing the modeEnum to be set to "2"
Am I going about this in the wrong way?