// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview A centralized listing for keycodes used by accessibility
* component extensions. Largely taken from
* ui/events/keycodes/keyboard_codes_posix.h, but with specific edits for Chrome
* OS and accessibility.
*/
import {TestImportManager} from './testing/test_import_manager.js';
export enum KeyCode {
UNKNOWN = 0,
POWER_BUTTON = 0,
CANCEL = 3,
BACK = 8,
TAB = 9,
BACKTAB = 10,
CLEAR = 12,
RETURN = 13,
SHIFT = 16,
CONTROL = 17,
MENU = 18,
ALT = 18,
PAUSE = 19,
CAPITAL = 20,
KANA = 21,
HANGUL = 21,
PASTE = 22,
JUNJA = 23,
FINAL = 24,
HANJA = 25,
KANJI = 25,
ESCAPE = 27,
CONVERT = 28,
NONCONVERT = 29,
ACCEPT = 30,
MODECHANGE = 31,
SPACE = 32,
PRIOR = 33,
NEXT = 34,
END = 35,
HOME = 36,
LEFT = 37,
UP = 38,
RIGHT = 39,
DOWN = 40,
SELECT = 41,
PRINT = 42,
EXECUTE = 43,
SNAPSHOT = 44,
INSERT = 45,
DELETE = 46,
HELP = 47,
ZERO = 48,
ONE = 49,
TWO = 50,
THREE = 51,
FOUR = 52,
FIVE = 53,
SIX = 54,
SEVEN = 55,
EIGHT = 56,
NINE = 57,
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
SEARCH = 91,
RWIN = 92,
APPS = 93,
SLEEP = 95,
NUMPAD0 = 96,
NUMPAD1 = 97,
NUMPAD2 = 98,
NUMPAD3 = 99,
NUMPAD4 = 100,
NUMPAD5 = 101,
NUMPAD6 = 102,
NUMPAD7 = 103,
NUMPAD8 = 104,
NUMPAD9 = 105,
MULTIPLY = 106,
ADD = 107,
SEPARATOR = 108,
SUBTRACT = 109,
DECIMAL = 110,
DIVIDE = 111,
F1 = 112,
F2 = 113,
F3 = 114,
F4 = 115,
F5 = 116,
F6 = 117,
F7 = 118,
F8 = 119,
F9 = 120,
F10 = 121,
F11 = 122,
F12 = 123,
F13 = 124,
F14 = 125,
F15 = 126,
F16 = 127,
F17 = 128,
F18 = 129,
F19 = 130,
F20 = 131,
F21 = 132,
F22 = 133,
F23 = 134,
F24 = 135,
NUMLOCK = 144,
SCROLL = 145,
WLAN = 151,
POWER = 152,
ASSISTANT = 153,
SETTINGS = 154,
PRIVACY_SCREEN_TOGGLE = 155,
LSHIFT = 160,
RSHIFT = 161,
LCONTROL = 162,
RCONTROL = 163,
LMENU = 164,
RMENU = 165,
BROWSER_BACK = 166,
BROWSER_FORWARD = 167,
BROWSER_REFRESH = 168,
BROWSER_STOP = 169,
BROWSER_SEARCH = 170,
BROWSER_FAVORITES = 171,
BROWSER_HOME = 172,
VOLUME_MUTE = 173,
VOLUME_DOWN = 174,
VOLUME_UP = 175,
MEDIA_NEXT_TRACK = 176,
MEDIA_PREV_TRACK = 177,
MEDIA_STOP = 178,
MEDIA_PLAY_PAUSE = 179,
MEDIA_LAUNCH_MAIL = 180,
MEDIA_LAUNCH_MEDIA_SELECT = 181,
MEDIA_LAUNCH_APP1 = 182,
MEDIA_LAUNCH_APP2 = 183,
OEM_1 = 186,
OEM_PLUS = 187,
OEM_COMMA = 188,
OEM_MINUS = 189,
OEM_PERIOD = 190,
OEM_2 = 191,
OEM_3 = 192,
BRIGHTNESS_DOWN = 216,
BRIGHTNESS_UP = 217,
KBD_BRIGHTNESS_DOWN = 218,
OEM_4 = 219,
OEM_5 = 220,
OEM_6 = 221,
OEM_7 = 222,
OEM_8 = 223,
ALTGR = 225,
OEM_102 = 226,
OEM_103 = 227,
OEM_104 = 228,
PROCESSKEY = 229,
COMPOSE = 230,
PACKET = 231,
KBD_BRIGHTNESS_UP = 232,
MEDIA_PLAY = 233,
MEDIA_PAUSE = 234,
OEM_ATTN = 240,
OEM_FINISH = 241,
OEM_COPY = 242,
DBE_SBCSCHAR = 243,
DBE_DBCSCHAR = 244,
OEM_BACKTAB = 245,
ATTN = 246,
CRSEL = 247,
EXSEL = 248,
EREOF = 249,
PLAY = 250,
ZOOM = 251,
NONAME = 252,
PA1 = 253,
OEM_CLEAR = 254,
}
const KEY_NAMES: Partial<Record<KeyCode, string>> = {
[KeyCode.POWER_BUTTON]: 'Power button',
[KeyCode.BACK]: 'Backspace',
[KeyCode.TAB]: 'Tab',
[KeyCode.RETURN]: 'Enter',
[KeyCode.SHIFT]: 'Shift',
[KeyCode.CONTROL]: 'Control',
[KeyCode.ALT]: 'Alt',
[KeyCode.ESCAPE]: 'Escape',
[KeyCode.SPACE]: 'Space',
[KeyCode.END]: 'end',
[KeyCode.HOME]: 'home',
[KeyCode.LEFT]: 'Left arrow',
[KeyCode.UP]: 'Up arrow',
[KeyCode.RIGHT]: 'Right arrow',
[KeyCode.DOWN]: 'Down arrow',
[KeyCode.INSERT]: 'Insert',
[KeyCode.DELETE]: 'Delete',
[KeyCode.ZERO]: '0',
[KeyCode.ONE]: '1',
[KeyCode.TWO]: '2',
[KeyCode.THREE]: '3',
[KeyCode.FOUR]: '4',
[KeyCode.FIVE]: '5',
[KeyCode.SIX]: '6',
[KeyCode.SEVEN]: '7',
[KeyCode.EIGHT]: '8',
[KeyCode.NINE]: '9',
[KeyCode.A]: 'A',
[KeyCode.B]: 'B',
[KeyCode.C]: 'C',
[KeyCode.D]: 'D',
[KeyCode.E]: 'E',
[KeyCode.F]: 'F',
[KeyCode.G]: 'G',
[KeyCode.H]: 'H',
[KeyCode.I]: 'I',
[KeyCode.J]: 'J',
[KeyCode.K]: 'K',
[KeyCode.L]: 'L',
[KeyCode.M]: 'M',
[KeyCode.N]: 'N',
[KeyCode.O]: 'O',
[KeyCode.P]: 'P',
[KeyCode.Q]: 'Q',
[KeyCode.R]: 'R',
[KeyCode.S]: 'S',
[KeyCode.T]: 'T',
[KeyCode.U]: 'U',
[KeyCode.V]: 'V',
[KeyCode.W]: 'W',
[KeyCode.X]: 'X',
[KeyCode.Y]: 'Y',
[KeyCode.Z]: 'Z',
[KeyCode.SEARCH]: 'Search',
[KeyCode.APPS]: 'Search',
[KeyCode.NUMPAD0]: '0',
[KeyCode.NUMPAD1]: '1',
[KeyCode.NUMPAD2]: '2',
[KeyCode.NUMPAD3]: '3',
[KeyCode.NUMPAD4]: '4',
[KeyCode.NUMPAD5]: '5',
[KeyCode.NUMPAD6]: '6',
[KeyCode.NUMPAD7]: '7',
[KeyCode.NUMPAD8]: '8',
[KeyCode.NUMPAD9]: '9',
[KeyCode.F4]: 'Toggle full screen',
[KeyCode.F11]: 'F11',
[KeyCode.F12]: 'F12',
[KeyCode.OEM_1]: 'Semicolon',
[KeyCode.OEM_PLUS]: 'Equal sign',
[KeyCode.OEM_COMMA]: 'Comma',
[KeyCode.OEM_MINUS]: 'Dash',
[KeyCode.OEM_PERIOD]: 'Period',
[KeyCode.OEM_2]: 'Forward slash',
[KeyCode.OEM_3]: 'Grave accent',
[KeyCode.OEM_4]: 'Open bracket',
[KeyCode.OEM_5]: 'Back slash',
[KeyCode.OEM_6]: 'Close bracket',
[KeyCode.OEM_7]: 'Single quote',
};
export namespace KeyCode {
export function name(code: KeyCode): string {
return KEY_NAMES[code] ?? '';
}
}
TestImportManager.exportForTesting(['KeyCode', KeyCode]);