【发布时间】:2015-04-11 14:38:26
【问题描述】:
我有很多 NSTextField,我想知道用户在编辑其中一个时是否按下了其中一个箭头键。函数
override func keyDown(theEvent: NSEvent) {
switch theEvent.character {
case NSRightArrowFunctionKey:
println(1)
moveGor(NSRightArrowFunctionKey)
case NSLeftArrowFunctionKey:
moveGor(NSLeftArrowFunctionKey)
case NSUpArrowFunctionKey:
moveVert(NSUpArrowFunctionKey)
case NSDownArrowFunctionKey:
moveVert(NSDownArrowFunctionKey)
default:
super.keyDown(theEvent)
}
}
似乎不起作用。有没有其他方法可以快速做到这一点?
编辑:
我有NSEvent的扩展名:
extension NSEvent {
var character: Int {
let str = charactersIgnoringModifiers!.utf16
return Int(str[str.startIndex])
}
}
我在之前的函数中使用过的
【问题讨论】:
-
我碰巧知道您有一个自定义的
NSEvent扩展名和character属性,但其他读者可能没有阅读您之前的问题。所以你也应该在这里添加。 -
@MartinR,好的,我已经添加了一些信息
标签: macos swift keydown nstextfield