Can’t change some menu shortcuts
bahman last edited by gferreira
I wanted to remove all menu shortcuts but apparently some are not added to the preferences yet. It's not possible to change them using a script either:
('Edit', 'Select All')
('Edit', 'Copy As Component')
('Edit', 'Paste in Layer')
('Python', 'Show Log File')
('Python', 'Jump Back')
('Window', 'New Space Center')
('Window', 'Zoom in A Bit')
('Window', 'Zoom out A Bit')
('Help', 'Application Help')
Sorry for nitpicking, but I need to remove them for a tool that its shortcuts can conflict with them.
I would advise to take a different route... :)
Prepolator and MetricsMachine extensions have their own shortcuts with an option to overwrite the existing shortcuts. There are just not enough modifiers and keys...
subscribe when your tool/window becomes active and unsubscribe when it deactivates!
import AppKit _specialCases = [ ("w", AppKit.NSCommandKeyMask), # close window, dont subscribe afterwards ("`", AppKit.NSCommandKeyMask), # jump to next window, dont subscribe afterwards ("`", AppKit.NSCommandKeyMask | AppKit.NSShiftKeyMask), # jump to prev window, don't subscribe afterwards ] class KeyEventMonitor(object): def __init__(self): self.monitor = None def subscribe(self): self.unsubscribe() self.monitor = AppKit.NSEvent.addLocalMonitorForEventsMatchingMask_handler_(AppKit.NSKeyDownMask, self.eventHandler) def unsubscribe(self): if self.monitor is not None: AppKit.NSEvent.removeMonitor_(self.monitor) self.monitor = None def eventHandler(self, event): inputKey = event.charactersIgnoringModifiers() eventModifiers = event.modifierFlags() # check if inputKey and eventModifiers match with your shortcuts found = True if inputKey = "s" and eventModifiers & AppKit.NSCommandKeyMask: # overwrite cmd s pass else: found = False if not found: self.unsubscribe() AppKit.NSApp().sendEvent_(event) if (inputKey, eventModifiers) not in _specialCases: # don't resubscribe when the window is closed self.subscribe()
bahman last edited by
I didn't think of that! Thank you, Frederik. This is very interesting.