Advertisement
lvs

KeysNet

lvs
Sep 16th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from AppKit import NSWorkspace
  3. from Cocoa import *
  4. from Foundation import *
  5. from PyObjCTools import AppHelper
  6. import socket
  7.  
  8. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  9.  
  10. class AppDelegate(NSObject):
  11.     def applicationDidFinishLaunching_(self, aNotification):
  12.         NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, handler)
  13.  
  14. def handler(event):
  15.     if NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName'] == 'Corona Simulator':
  16.         s = unicode(event).split(' ')
  17.         if s[8]:
  18.             s = s[8][-2:-1]
  19.             if (s >= 'a' and s <= 'z') or s == '`' or s == '[' or s == ']':
  20.                 sock.sendto(s, ('127.0.0.1', 5000))
  21.        
  22. def main():
  23.     app = NSApplication.sharedApplication()
  24.     delegate = AppDelegate.alloc().init()
  25.     NSApp().setDelegate_(delegate)
  26.     AppHelper.runEventLoop()
  27.  
  28. if __name__ == '__main__':
  29.    main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement