Swift OSX key event
override func keyDown(with event: NSEvent) {
if (event.keyCode == 1){
//do whatever when the s key is pressed
print("S key pressed")
}
}
Updated for SWIFT 3
SWIFT 4: I created a repo solving this problem on my games. I mainly use this with my MTKView but should work with NSViews too.
https://github.com/twohyjr/NSView-Keyboard-and-Mouse-Input
Here is some example code:
override func keyDown(theEvent: NSEvent) {
if (theEvent.keyCode == 1){
//do whatever when the s key is pressed
}
}
Key codes: