Skip to content

Instantly share code, notes, and snippets.

@cuilkid
Created June 29, 2012 22:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuilkid/3020934 to your computer and use it in GitHub Desktop.
Save cuilkid/3020934 to your computer and use it in GitHub Desktop.
from Cocoa import NSApp, NSEvent, NSKeyDownMask # , NSApplication
from Foundation import NSObject, NSLog
from PyObjCTools import AppHelper
from AppKit import NSApplication
# https://bitbucket.org/ronaldoussoren/pyobjc/
# you have to enable access for assistive devices in 'System Preferences>Universal Access>Keyboard'
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, notification):
print 'A'
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, handler)
print 'B'
def handler(event):
try:
print 'C'
NSLog(u"%@", event)
print 'D'
except KeyboardInterrupt:
AppHelper.stopEventLoop()
def main():
app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
NSApp().setDelegate_(delegate)
print 'E'
AppHelper.runEventLoop()
if __name__ == '__main__':
main()
@ljos
Copy link

ljos commented Jun 30, 2012

You need to install the dependencies again for python2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment