0

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.

mrle4w
  • 101
  • 1
  • 5
  • Does this answer your question? [Capture Global Keydown Events (not simply observe)](https://stackoverflow.com/questions/35871788/capture-global-keydown-events-not-simply-observe) – Asperi Apr 25 '20 at 15:55
  • Does this answer your question? [How to detect keystrokes globally in Swift on macOS?](https://stackoverflow.com/questions/45986756/how-to-detect-keystrokes-globally-in-swift-on-macos) – Willeke Apr 26 '20 at 07:51

0 Answers0