Cocoa 键码在哪里?

Where are all the Cocoa keycodes?

我正在尝试使用 Cocoa 创建游戏,我需要获得用户输入。似乎没有所有键码的可用列表。我应该使用键码吗?我找到了某些值,例如 NSUpArrowFunctionKey,但没有找到其他键。关于这个的更老的问题的答案都已过时,使用 Carbon,链接断开。

我没有找到类似枚举的东西,但这似乎包含了大部分(如果不是全部的话)数字键代码。

http://macbiblioblog.blogspot.com/2014/12/key-codes-for-function-and-special-keys.html

以防万一 blog/link 出现故障:

Zero            29
One             18
Two             19
Three           20
Four            21
Five            23
Six             22
Seven           26
Eight           28
Nine            25
A               0
B               11
C               8
D               2
E               14
F               3
G               5
H               4
I               34
J               38
K               40
L               37
M               46
N               45
O               31
P               35
Q               12
R               15
S               1
T               17
U               32
V               9
W               13
X               7
Y               16
Z               6
SectionSign     10
Grave           50
Minus           27
Equal           24
LeftBracket     33
RightBracket    30
Semicolon       41
Quote           39
Comma           43
Period          47
Slash           44
Backslash       42
Keypad0 0       82
Keypad1 1       83
Keypad2 2       84
Keypad3 3       85
Keypad4 4       86
Keypad5 5       87
Keypad6 6       88
Keypad7 7       89
Keypad8 8       91
Keypad9 9       92
KeypadDecimal   65
KeypadMultiply  67
KeypadPlus      69
KeypadDivide    75
KeypadMinus     78
KeypadEquals    81
KeypadClear     71
KeypadEnter     76
Space           49
Return          36
Tab             48
Delete          51
ForwardDelete   117
Linefeed        52
Escape          53
Command         55
Shift           56
CapsLock        57
Option          58
Control         59
RightShift      60
RightOption     61
RightControl    62
Function        63
F1              122
F2              120
F3              99
F4              118
F5              96
F6              97
F7              98
F8              100
F9              101
F10             109
F11             103
F12             111
F13             105
F14             107
F15             113
F16             106
F17             64
F18             79
F19             80
F20             90
VolumeUp        72
VolumeDown      73
Mute            74
Help/Insert     114
Home            115
End             119
PageUp          116
PageDown        121
LeftArrow       123
RightArrow      124
DownArrow       125
UpArrow         126

虚拟键码在 Events.h 中声明 (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h)

Discussion:

These constants are the virtual keycodes defined originally in Inside Mac Volume V, pg. V-191. They identify physical keys on a keyboard. Those constants with "ANSI" in the name are labeled according to the key position on an ANSI-standard US keyboard. For example, kVK_ANSI_A indicates the virtual keycode for the key with the letter 'A' in the US keyboard layout. Other keyboard layouts may have the 'A' key label on a different physical key; in this case, pressing 'A' will generate a different virtual keycode.