Skip to content

Commit ba3e3e3

Browse files
authored
Merge pull request #2 from JE-Chen/dev
Create osx_keyboard_listener.py
2 parents 5e42dae + 3b6dca0 commit ba3e3e3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from Cocoa import *
2+
import time
3+
from Foundation import *
4+
from PyObjCTools import AppHelper
5+
6+
class AppDelegate(NSObject):
7+
def applicationDidFinishLaunching_(self, aNotification):
8+
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, handler)
9+
10+
def handler(event):
11+
print(event)
12+
print(str(hex(event.keyCode())))
13+
14+
app = NSApplication.sharedApplication()
15+
delegate = AppDelegate.alloc().init()
16+
NSApp().setDelegate_(delegate)
17+
AppHelper.runEventLoop()

0 commit comments

Comments
 (0)