我在哪里可以找到与 Cocoa 的 NSEvent 类一起使用的关键代码列表? [英] Where can I find a list of key codes for use with Cocoa's NSEvent class?
问题描述
我正在寻找可与 Cocoa 的 NSEvent
类一起使用的可用键代码的完整列表.NSEvent
类有一个keyCode
属性,定义为unsigned short
.以下代码在放置在适当的 UI 对象中时,将在按键代码被按下时回显:
I'm looking for a comprehensive list of the available key codes that can be used with Cocoa's NSEvent
class. The NSEvent
class has a keyCode
property, which is defined as unsigned short
. The following code, when placed in an appropriate UI object, will echo the key codes as they are pressed:
- (void)keyDown:(NSEvent *)theEvent
{
NSLog(@"%d", [theEvent keyCode]);
}
从这段代码中,我可以很容易地看到哪些代码与某些键匹配,但我想在某个地方找到一个列出所有这些键的官方文档.我希望 Apple 在某处有一个如下所示的头文件:
From this code, I can easily see which codes match certain keys, but I would like to find an official document somewhere that lists all of them. I expected Apple to have a header file somewhere that looked like this:
enum {
...
NSKeyCodeLeftArrow = 123,
NSKeyCodeRightArrow = 124,
...
};
但如果有的话,我还没有找到.
But if there is one, I have yet to find it.
推荐答案
据我所知,没有枚举或键码列表.但是,要获得类似的行为,您可以在 keyDown 中调用 interpretKeyEvents:: 这将调用适当的操作方法,所有这些方法都记录在 NSResponder 中(例如 moveLeft:, insertTab: 等)
As far as I know, there is no enum or list of key codes. However, to get similar behavior, you can call interpretKeyEvents: in keyDown: which will call appropriate action methods, all of which are documented in NSResponder (e.g. moveLeft:, insertTab:, etc.)
这篇关于我在哪里可以找到与 Cocoa 的 NSEvent 类一起使用的关键代码列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!