I need to display a CGKeyCode
in a user-readable way.
Here is an example:
For characters and letters:
0 -> "a"
18 -> "1"
For specific keys:
49 -> "Space"
83 -> "Numpad 1"
80 -> "F19"
Depending on the keyboard layout the names will have to change. The keycode only specifies the key location, independent from its characters. For example the keycode 16
will be "y" on a QWERTY keyboard, but a "z" on a QWERTZ keyboard.
Since this should be a common problem and is used in OS X for assigning keyboard shortcuts, I wonder if there is any build in functionallity, or a library, that I could use to do that?
Writing switch-case statements for each keyboard layout by hand seems to be a huge task …
I found two enumerations in events.h in Carbon.
One for keyCodes with universal names, which are independent from keyboard layouts and one for keyboard layout specific names on a ANSI-standard US keyboard.
The names follow the naming convention of kVK_F19
or kVK_ANSI_RightBracket
. However, I could only use those with a US keyboard layout and the names would be nicer in a simpler way like F19
or Right Bracket
.