I am writing a small menu bar app for macOS and need to listen to key presses systemwide. How can I do this in the AppDelegate class?
I found this Swift OSX key event but I can't figure out how to implement that into the AppDelegate.
But when I put the following code in there I get an error:
override func keyDown(with event: NSEvent) {
if (event.keyCode == 1){
//do whatever when the s key is pressed
print("S key pressed")
}
}
Method does not override any method from its superclass
For some context: I want to make a small app for myself to optimize my workflow. I can't fit all of my shortcuts onto one keyboard which is why I have a second one connected. Under Windows I can use software like LuaMacros and AutoHotkey to add Macros to the second keyboard specifically . Unfortunately I was unable to find equivalent software for macOS. So after I figured out how to check for key presses, I need to check which keyboard is actually being pressed. If you know a way of doing that, please let me know as that is my next step.
Thanks for any help.