Hot keys for mac kill program
I converted the Quartz event into a NSEvent, because all the information I could find on Mac multimedia keys was referring to that class. KeyEvent = NSEvent.eventWithCGEvent_(event) # Convert the Quartz CGEvent into something more useful The callback should have the following signature (it implements the CGEventTapCallBack method from the Quartz API: def keyboardTapCallback(proxy, type_, event, refcon): Quartz.CGEventMaskBit(Quartz.kCGEventKeyUp) for key up events. I defined a tap for system defined keys only (media keys) you'll have to specify a different event mask ( CGEventMaskBit with one or more Event Types) e.g. # and run! This won't return until we exit or are terminated. RunLoopSource = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0) Quartz.CGEventMaskBit(NSSystemDefined), # NSSystemDefined for media keys Quartz.kCGEventTapOptionListenOnly, # Listening is enough Quartz.kCGHeadInsertEventTap, # Insert wherever, we do not filter Using a Mac kill process can force quit problem applications in an instant and free up precious resources, like processing power and memory, so that your system runs more smoothly. Quartz.kCGSessionEventTap, # Session level is enough for our needs If your Mac is running slower than usual, or you have applications that have frozen and refuse to quit, you may need to kill some running processes.
# Set up a tap, with type of tap, location, options and event mask
#HOT KEYS FOR MAC KILL PROGRAM CODE#
The following code registers a python callback which is passed global key presses, and starts the event loop: import Quartzįrom AppKit import NSKeyUp, NSSystemDefined, NSEvent I used the Quartz CGEventTapCreate hook and event loop, and the Cocoa AppKit framework to decipher key codes to achieve this. I recently coded up an extension to quodlibet capturing multimedia keys (since absorbed into quodlibet itself) for your setup the same process applies.