From 3b6dca0503f120277f8c13d20c42efa8e5b9b325 Mon Sep 17 00:00:00 2001 From: JE-Chen Date: Fri, 8 Oct 2021 07:03:20 -0700 Subject: [PATCH] Create osx_keyboard_listener.py add osx keyboard listener --- .../osx/listener/osx_keyboard_listener.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 je_auto_control/osx/listener/osx_keyboard_listener.py diff --git a/je_auto_control/osx/listener/osx_keyboard_listener.py b/je_auto_control/osx/listener/osx_keyboard_listener.py new file mode 100644 index 0000000..777cdde --- /dev/null +++ b/je_auto_control/osx/listener/osx_keyboard_listener.py @@ -0,0 +1,17 @@ +from Cocoa import * +import time +from Foundation import * +from PyObjCTools import AppHelper + +class AppDelegate(NSObject): + def applicationDidFinishLaunching_(self, aNotification): + NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, handler) + +def handler(event): + print(event) + print(str(hex(event.keyCode()))) + +app = NSApplication.sharedApplication() +delegate = AppDelegate.alloc().init() +NSApp().setDelegate_(delegate) +AppHelper.runEventLoop() \ No newline at end of file