This allows you to change the character codes associated with an NSEvent. You may want to do this if you override NSTableView's keyDown: method to support j/k movements.
Usage:
theEvent.eventByChangingKeyToKey(NSUpArrowFunctionKey)
extension NSEvent { | |
func eventByChangingKeyToKey(key: Int) -> NSEvent? { | |
var char = unichar(key) | |
let characterString = NSString(characters: &char, length: 1) | |
return NSEvent.keyEventWithType(type, | |
location: locationInWindow, | |
modifierFlags: modifierFlags, | |
timestamp: timestamp, | |
windowNumber: windowNumber, | |
context: context, | |
characters: characterString, | |
charactersIgnoringModifiers: characterString, | |
isARepeat: ARepeat, | |
keyCode: char) | |
} | |
} |