Created
June 29, 2012 22:06
-
-
Save cuilkid/3020934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to install the dependencies again for python2.7