I'm trying to detect if the U
key is pressed or not, and if it is it should print("BUT...BUT..");
but I'm not sure how to check for different keys, as the documentation for key presses is quite bad.. I found an answer with keycodes but they only work for QWERTY keyboards
viewcontroller.swift
override func viewDidLoad(){
super.viewDidLoad();
let f = Foo();
f.doSonethimg();
}
override func keyDown(theEvent: NSEvent){
let f = Foo();
f.KeyDown(theEvent);
}
Foo.swift
public func doSonething(){
print("Hello from Dylib");
}
public func keyDown(event: NSEvent){
if let keyString = theEvent.charactersIgnoringModifiers where keyString == "u" || keyString == "U" {
Swift.print("BUT...BUT…")
}
}
How would I change the keyDown
Function to respond to U
and what is it's default key?
I've looked at - Detecting key press event in Swift and https://superuser.com/questions/399430/mouse-button-and-keypress-counter-for-mac-os-x
also see - https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html - Overriding the keyDown: Method