JFLib

plat/keycode.rs#

Source: lib/plat/keycode.rs

keycode -- (G7a) where a key sits on the keyboard, the same number on every platform: the USB
HID usage IDs of the keyboard page (page 7), whatever the layout prints on the key

  KC_*                              the usages (KC_W is the key right of Q on a US keyboard: the
                                    Z of a French one, still KC_W)
  key_code(scancode) -> code        Event::x of a key event on this platform -> its usage
                                    (0: unknown); KeyEvent::code of the UI
  key_scancode(code) -> scancode    the other way (scripts, tests); 0: this platform has none
  key_code_set1(sc) / key_code_evdev(code) / key_code_mac(kvk)   the tables of the
                                    platforms, on every target (tests): Windows' scan codes
                                    of set 1 (0xE0.. for the extended keys, as Event::x),
                                    Linux's evdev codes, the virtual key codes of macOS (kVK_*)
  key_code_name(code) / key_code_from_name(name)   the browser's KeyboardEvent.code names
                                    ("KeyW", "ShiftLeft"); "" / 0 unknown
  key_label(code) -> Option<String> what the current layout prints on that key ("Z" for KC_W
                                    on a French keyboard), None where the platform does not
                                    say (the browser, Android, iOS) or the key has no label

What Event::x of E_KEY_DOWN / E_KEY_UP holds per platform: Windows' scan code (set 1, 0xE0..
extended), Linux's evdev code (X11 and Wayland), the usage itself on macOS, iOS and in the
browser (their own codes are turned into usages where the event is made); Android 0.

The rows follow the USB HID usage tables (keyboard page) and the mapping of the UI Events
KeyboardEvent.code specification (W3C) to the native codes of each system.
/// (G7a) USB HID usages of the keyboard page: where a key sits (KeyEvent::code)
KC_A: u32 = 0x04
KC_B: u32 = 0x05
KC_C: u32 = 0x06
KC_D: u32 = 0x07
KC_E: u32 = 0x08
KC_F: u32 = 0x09
KC_G: u32 = 0x0A
KC_H: u32 = 0x0B
KC_I: u32 = 0x0C
KC_J: u32 = 0x0D
KC_K: u32 = 0x0E
KC_L: u32 = 0x0F
KC_M: u32 = 0x10
KC_N: u32 = 0x11
KC_O: u32 = 0x12
KC_P: u32 = 0x13
KC_Q: u32 = 0x14
KC_R: u32 = 0x15
KC_S: u32 = 0x16
KC_T: u32 = 0x17
KC_U: u32 = 0x18
KC_V: u32 = 0x19
KC_W: u32 = 0x1A
KC_X: u32 = 0x1B
KC_Y: u32 = 0x1C
KC_Z: u32 = 0x1D
KC_1: u32 = 0x1E
KC_2: u32 = 0x1F
KC_3: u32 = 0x20
KC_4: u32 = 0x21
KC_5: u32 = 0x22
KC_6: u32 = 0x23
KC_7: u32 = 0x24
KC_8: u32 = 0x25
KC_9: u32 = 0x26
KC_0: u32 = 0x27
KC_ENTER: u32 = 0x28
KC_ESCAPE: u32 = 0x29
KC_BACKSPACE: u32 = 0x2A
KC_TAB: u32 = 0x2B
KC_SPACE: u32 = 0x2C
KC_MINUS: u32 = 0x2D
KC_EQUAL: u32 = 0x2E
KC_BRACKET_LEFT: u32 = 0x2F
KC_BRACKET_RIGHT: u32 = 0x30
/// the US layout's backslash; on an ISO keyboard the key left of Enter (# on a German one)
KC_BACKSLASH: u32 = 0x31
KC_SEMICOLON: u32 = 0x33
KC_QUOTE: u32 = 0x34
/// left of 1 on a US keyboard (` ~), ^ on a German one
KC_BACKQUOTE: u32 = 0x35
KC_COMMA: u32 = 0x36
KC_PERIOD: u32 = 0x37
KC_SLASH: u32 = 0x38
KC_CAPS_LOCK: u32 = 0x39
KC_F1: u32 = 0x3A
KC_F2: u32 = 0x3B
KC_F3: u32 = 0x3C
KC_F4: u32 = 0x3D
KC_F5: u32 = 0x3E
KC_F6: u32 = 0x3F
KC_F7: u32 = 0x40
KC_F8: u32 = 0x41
KC_F9: u32 = 0x42
KC_F10: u32 = 0x43
KC_F11: u32 = 0x44
KC_F12: u32 = 0x45
KC_PRINT_SCREEN: u32 = 0x46
KC_SCROLL_LOCK: u32 = 0x47
KC_PAUSE: u32 = 0x48
KC_INSERT: u32 = 0x49
KC_HOME: u32 = 0x4A
KC_PAGE_UP: u32 = 0x4B
KC_DELETE: u32 = 0x4C
KC_END: u32 = 0x4D
KC_PAGE_DOWN: u32 = 0x4E
KC_RIGHT: u32 = 0x4F
KC_LEFT: u32 = 0x50
KC_DOWN: u32 = 0x51
KC_UP: u32 = 0x52
KC_NUM_LOCK: u32 = 0x53
KC_NUMPAD_DIVIDE: u32 = 0x54
KC_NUMPAD_MULTIPLY: u32 = 0x55
KC_NUMPAD_SUBTRACT: u32 = 0x56
KC_NUMPAD_ADD: u32 = 0x57
KC_NUMPAD_ENTER: u32 = 0x58
KC_NUMPAD1: u32 = 0x59
KC_NUMPAD2: u32 = 0x5A
KC_NUMPAD3: u32 = 0x5B
KC_NUMPAD4: u32 = 0x5C
KC_NUMPAD5: u32 = 0x5D
KC_NUMPAD6: u32 = 0x5E
KC_NUMPAD7: u32 = 0x5F
KC_NUMPAD8: u32 = 0x60
KC_NUMPAD9: u32 = 0x61
KC_NUMPAD0: u32 = 0x62
KC_NUMPAD_DECIMAL: u32 = 0x63
/// the ISO keyboard's key left of Z (< > on a German one)
KC_INTL_BACKSLASH: u32 = 0x64
KC_CONTEXT_MENU: u32 = 0x65
KC_POWER: u32 = 0x66
KC_NUMPAD_EQUAL: u32 = 0x67
KC_F13: u32 = 0x68
KC_F14: u32 = 0x69
KC_F15: u32 = 0x6A
KC_F16: u32 = 0x6B
KC_F17: u32 = 0x6C
KC_F18: u32 = 0x6D
KC_F19: u32 = 0x6E
KC_F20: u32 = 0x6F
KC_F21: u32 = 0x70
KC_F22: u32 = 0x71
KC_F23: u32 = 0x72
KC_F24: u32 = 0x73
KC_VOLUME_MUTE: u32 = 0x7F
KC_VOLUME_UP: u32 = 0x80
KC_VOLUME_DOWN: u32 = 0x81
KC_NUMPAD_COMMA: u32 = 0x85
KC_INTL_RO: u32 = 0x87
KC_KANA_MODE: u32 = 0x88
KC_INTL_YEN: u32 = 0x89
KC_CONVERT: u32 = 0x8A
KC_NON_CONVERT: u32 = 0x8B
KC_LANG1: u32 = 0x90
KC_LANG2: u32 = 0x91
KC_CONTROL_LEFT: u32 = 0xE0
KC_SHIFT_LEFT: u32 = 0xE1
KC_ALT_LEFT: u32 = 0xE2
/// the left Windows / Super / Command key
KC_META_LEFT: u32 = 0xE3
KC_CONTROL_RIGHT: u32 = 0xE4
KC_SHIFT_RIGHT: u32 = 0xE5
/// the right Alt (AltGr on many layouts)
KC_ALT_RIGHT: u32 = 0xE6
KC_META_RIGHT: u32 = 0xE7
  • fn key_code_set1(sc: u32) -> u32 (G7a) the usage of a Windows scan code of set 1 as a key event of Windows carries it in Event::x (0xE0.. for the extended keys); 0 unknown. Alt+Print (0x54) is Print, Ctrl+Pause (0xE046) is Pause

  • fn key_code_evdev(code: u32) -> u32 (G7a) the usage of a Linux evdev key code (KEY_*, the X keycode minus 8); 0 unknown

  • fn key_code_mac(kvk: u32) -> u32 (G7a) the usage of a macOS virtual key code (kVK_*, NSEvent.keyCode; kVK_ANSI_A is 0); 0 unknown

  • fn key_code_name(code: u32) -> &'static str (G7a) the browser's KeyboardEvent.code name of a usage ("KeyW", "ShiftLeft"); "" unknown

  • fn key_code_from_name(name: &str) -> u32 (G7a) the usage of a KeyboardEvent.code name; 0 unknown. Older names of Firefox ("OSLeft", "OSRight", "VolumeMute", "VolumeUp", "VolumeDown") too

  • fn key_code(scancode: u32) -> u32 (G7a) the usage (KC_*) of a key event's Event::x on this platform: Windows' scan code, Linux's and Android's evdev code, on macOS, iOS and in the browser the usage itself; 0 unknown

  • fn key_scancode(code: u32) -> u32 (G7a) Event::x of a key event on this platform for a usage (KC_*): what key_code turns back into it; 0 where this platform has no code for it

  • fn key_label(code: u32) -> Option<String> (G7a) what the current keyboard layout prints on the key at usage code: its character without Shift in upper case ("Z" for KC_W on a French keyboard, "Ü" for KC_BRACKET_LEFT on a German one), else the system's name of the key where it has one (Windows: "Esc", "Enter" in the system's language). Windows (the thread's layout), Linux (the keymap of X11 or Wayland, once a window has the keyboard), macOS (the current input source); None in the browser, on Android and iOS and for keys the layout gives nothing

  • fn key_code_rows_test() -> alloc::vec::Vec<(u32, u32, u32, u32, &'static str)> (test aid, plattest --test input) every row of the table: (usage, Windows scan code, evdev code, macOS key code or 0xFF, the browser's name)

Source: docs/API.md in the JFLib repository.