Skip to content

Instantly share code, notes, and snippets.

@jimratliff
Last active February 21, 2024 10:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimratliff/227088cc936065598bedfd91c360334e to your computer and use it in GitHub Desktop.
Save jimratliff/227088cc936065598bedfd91c360334e to your computer and use it in GitHub Desktop.
ASCII and Mac Virtual Key codes for editing com.apple.symbolichotkeys plist. (See sources/information in first comment.) #dotfiles #character_codes #symbolichotkeys
Keyboard Label Character ASCII code (Parameter #1) Mac Virtual Key Code (Parameter #2) Layout dependence?
0 0 48 029 ANSI-US
1 1 49 018 ANSI-US
2 2 50 019 ANSI-US
3 3 51 020 ANSI-US
4 4 52 021 ANSI-US
5 5 53 023 ANSI-US
6 6 54 022 ANSI-US
7 7 55 026 ANSI-US
8 8 56 028 ANSI-US
9 9 57 025 ANSI-US
A a 97 000 ANSI-US
B b 98 011 ANSI-US
C c 99 008 ANSI-US
D d 100 002 ANSI-US
E e 101 014 ANSI-US
F f 102 003 ANSI-US
G g 103 005 ANSI-US
H h 104 004 ANSI-US
I i 105 034 ANSI-US
J j 106 038 ANSI-US
K k 107 040 ANSI-US
L l 108 037 ANSI-US
M m 109 046 ANSI-US
N n 110 045 ANSI-US
O o 111 031 ANSI-US
P p 112 035 ANSI-US
Q q 113 012 ANSI-US
R r 114 015 ANSI-US
S s 115 001 ANSI-US
T t 116 017 ANSI-US
U u 117 032 ANSI-US
V v 118 009 ANSI-US
W w 119 013 ANSI-US
X x 120 007 ANSI-US
Y y 121 016 ANSI-US
Z z 122 006 ANSI-US
F1 65535 122 Independent
F2 65535 120 Independent
F3 65535 099 Independent
F4 65535 118 Independent
F5 65535 096 Independent
F6 65535 097 Independent
F7 65535 098 Independent
F8 65535 100 Independent
F9 65535 101 Independent
F10 65535 109 Independent
F11 65535 103 Independent
F12 65535 111 Independent
F13 65535 105 Independent
F14 65535 107 Independent
F15 65535 113 Independent
F16 65535 106 Independent
F17 65535 064 Independent
F18 65535 079 Independent
F19 65535 080 Independent
F20 65535 090 Independent
Keypad0        65535 082 ANSI-US
Keypad1        65535 083 ANSI-US
Keypad2        65535 084 ANSI-US
Keypad3        65535 085 ANSI-US
Keypad4        65535 086 ANSI-US
Keypad5        65535 087 ANSI-US
Keypad6        65535 088 ANSI-US
Keypad7        65535 089 ANSI-US
Keypad8        65535 091 ANSI-US
Keypad9        65535 092 ANSI-US
KeypadClear    65535 071 ANSI-US
KeypadDecimal  65535 065 ANSI-US
KeypadDivide   65535 075 ANSI-US
KeypadEnter    65535 076 ANSI-US
KeypadEquals   65535 081 ANSI-US
KeypadMinus    65535 078 ANSI-US
KeypadMultiply 65535 067 ANSI-US
KeypadPlus     65535 069 ANSI-US
Backslash      \ 92 042 ANSI-US
CapsLock      65535 057 Independent
Comma          , 44 043 ANSI-US
Command       65535 055 Independent
Control       65535 059 Independent
Delete         65535 051 Independent
DownArrow     65535 125 Independent
End           65535 119 Independent
Equal          = 61 024 ANSI-US
Escape         27 053 Independent
ForwardDelete 65535 117 Independent
Function      65535 063 Independent
Grave          ` 96 050 ANSI-US
Help          65535 114 Independent
Home          65535 115 Independent
LeftArrow     65535 123 Independent
LeftBracket    [ 91 033 ANSI-US
Minus          - 45 027 ANSI-US
Mute          65535 074 Independent
Option        65535 058 Independent
PageDown      65535 121 Independent
PageUp        65535 116 Independent
Period         . 46 047 ANSI-US
Quote          ' 39 039 ANSI-US
Return        65535 036 Independent
RightArrow    65535 124 Independent
RightBracket   ] 93 030 ANSI-US
RightCommand  65535 054 Independent
RightControl  65535 062 Independent
RightOption   65535 061 Independent
RightShift    65535 060 Independent
Semicolon      ; 59 041 ANSI-US
Shift         65535 056 Independent
Slash          / 47 044 ANSI-US
Space         32 049 Independent
Tab           9 048 Independent
UpArrow       65535 126 Independent
VolumeDown    65535 073 Independent
VolumeUp      65535 072 Independent
@jimratliff
Copy link
Author

jimratliff commented Apr 22, 2018

This table is useful for editing the com.apple.symbolichotkeys plist in macOS. Regarding editing the com.apple.symbolichotkeys plist, see, for example:
*Charles Edge, "Defaults & symbolichotkeys in Mac OS X," krypted.com, September 7, 2010.
*fracai et al., "Documenting com.apple.symbolichotkeys.plist," Mac OS X Hints, 11/9/2010, via WayBackMachine.

Related: See Gist "Masks for all combinations of modifier-key presses (involving Shift, Option, Command, and Control) in macOS."

The ASCII code for the unmodified key press is used in the first parameter (Item 0) of the parameters array in the hotkey's entry in the symbolichotkeys dictionary. When the ASCII code does not exist, the value 65535 is used instead.

The Virtual Key code is used in the second parameter (Item 1) of the parameters array in the hotkey's entry in the symbolichotkeys dictionary.

Regarding the ASCII codes:
Although the key labeled "A" depicts an upper-case "A", unmodified the character it produces is lower-case "a". Thus the ASCII code corresponds to lower-case "a". Ditto for the other letters of the alphabet.

Source for Mac virtual key code as a function of keyboard label: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h

These constants are the virtual keycodes defined originally in Inside Mac Volume V, pg. V-191. They identify physical keys on a keyboard.

Entries labeled “ANSI-US”: These constants are labeled according to the key position on an ANSI-standard US keyboard. For example, "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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment