22

Can someone point me to the list of key codes that come from getKeyCode() in numeric form so that for example if I look up 72 I see "]" and if I look up 24 I see "vol up".

I have been looking for an hour and the answer is not an ASCII table. That would be too easy...

I am getting key codes off my mouse-presenter and trying to intercept them. There is one key that puts out 57 and 117 that I cannot intercept and I wanted to decode it before asking a question about it but can't find the reference. I think 117 is shift but I don't know what 57 is. That key on the presenter takes me out of my app even if I intercept it.

Allen Edwards
  • 1,488
  • 1
  • 27
  • 44

13 Answers13

24

List Of Key codes:

a - z-> 29 - 54

"0" - "9"-> 7 - 16

BACK BUTTON - 4, MENU BUTTON - 82

UP-19, DOWN-20, LEFT-21, RIGHT-22

SELECT (MIDDLE) BUTTON - 23

SPACE - 62, SHIFT - 59, ENTER - 66, BACKSPACE - 67

AnanThDev
  • 337
  • 2
  • 16
22

#Complete list of key codes

Some of the other lists here are incomplete. The complete list can be found in the KeyEvent source code or documentation. The source code is ordered by integer value so I will use that here.

(Repetitive text removed to save space, all key codes are public static final int.)

/** Unknown key code. */
KEYCODE_UNKNOWN = 0;
/** Soft Left key.
 * Usually situated below the display on phones and used as a multi-function
 * feature key for selecting a software defined function shown on the bottom left
 * of the display. */
KEYCODE_SOFT_LEFT = 1;
/** Soft Right key.
 * Usually situated below the display on phones and used as a multi-function
 * feature key for selecting a software defined function shown on the bottom right
 * of the display. */
KEYCODE_SOFT_RIGHT = 2;
/** Home key.
 * This key is handled by the framework and is never delivered to applications. */
KEYCODE_HOME = 3;
/** Back key. */
KEYCODE_BACK = 4;
/** Call key. */
KEYCODE_CALL = 5;
/** End Call key. */
KEYCODE_ENDCALL = 6;
/** '0' key. */
KEYCODE_0 = 7;
/** '1' key. */
KEYCODE_1 = 8;
/** '2' key. */
KEYCODE_2 = 9;
/** '3' key. */
KEYCODE_3 = 10;
/** '4' key. */
KEYCODE_4 = 11;
/** '5' key. */
KEYCODE_5 = 12;
/** '6' key. */
KEYCODE_6 = 13;
/** '7' key. */
KEYCODE_7 = 14;
/** '8' key. */
KEYCODE_8 = 15;
/** '9' key. */
KEYCODE_9 = 16;
/** '*' key. */
KEYCODE_STAR = 17;
/** '#' key. */
KEYCODE_POUND = 18;
/** Directional Pad Up key.
 * May also be synthesized from trackball motions. */
KEYCODE_DPAD_UP = 19;
/** Directional Pad Down key.
 * May also be synthesized from trackball motions. */
KEYCODE_DPAD_DOWN = 20;
/** Directional Pad Left key.
 * May also be synthesized from trackball motions. */
KEYCODE_DPAD_LEFT = 21;
/** Directional Pad Right key.
 * May also be synthesized from trackball motions. */
KEYCODE_DPAD_RIGHT = 22;
/** Directional Pad Center key.
 * May also be synthesized from trackball motions. */
KEYCODE_DPAD_CENTER = 23;
/** Volume Up key.
 * Adjusts the speaker volume up. */
KEYCODE_VOLUME_UP = 24;
/** Volume Down key.
 * Adjusts the speaker volume down. */
KEYCODE_VOLUME_DOWN = 25;
/** Power key. */
KEYCODE_POWER = 26;
/** Camera key.
 * Used to launch a camera application or take pictures. */
KEYCODE_CAMERA = 27;
/** Clear key. */
KEYCODE_CLEAR = 28;
/** 'A' key. */
KEYCODE_A = 29;
/** 'B' key. */
KEYCODE_B = 30;
/** 'C' key. */
KEYCODE_C = 31;
/** 'D' key. */
KEYCODE_D = 32;
/** 'E' key. */
KEYCODE_E = 33;
/** 'F' key. */
KEYCODE_F = 34;
/** 'G' key. */
KEYCODE_G = 35;
/** 'H' key. */
KEYCODE_H = 36;
/** 'I' key. */
KEYCODE_I = 37;
/** 'J' key. */
KEYCODE_J = 38;
/** 'K' key. */
KEYCODE_K = 39;
/** 'L' key. */
KEYCODE_L = 40;
/** 'M' key. */
KEYCODE_M = 41;
/** 'N' key. */
KEYCODE_N = 42;
/** 'O' key. */
KEYCODE_O = 43;
/** 'P' key. */
KEYCODE_P = 44;
/** 'Q' key. */
KEYCODE_Q = 45;
/** 'R' key. */
KEYCODE_R = 46;
/** 'S' key. */
KEYCODE_S = 47;
/** 'T' key. */
KEYCODE_T = 48;
/** 'U' key. */
KEYCODE_U = 49;
/** 'V' key. */
KEYCODE_V = 50;
/** 'W' key. */
KEYCODE_W = 51;
/** 'X' key. */
KEYCODE_X = 52;
/** 'Y' key. */
KEYCODE_Y = 53;
/** 'Z' key. */
KEYCODE_Z = 54;
/** ',' key. */
KEYCODE_COMMA = 55;
/** '.' key. */
KEYCODE_PERIOD = 56;
/** Left Alt modifier key. */
KEYCODE_ALT_LEFT = 57;
/** Right Alt modifier key. */
KEYCODE_ALT_RIGHT = 58;
/** Left Shift modifier key. */
KEYCODE_SHIFT_LEFT = 59;
/** Right Shift modifier key. */
KEYCODE_SHIFT_RIGHT = 60;
/** Tab key. */
KEYCODE_TAB = 61;
/** Space key. */
KEYCODE_SPACE = 62;
/** Symbol modifier key.
 * Used to enter alternate symbols. */
KEYCODE_SYM = 63;
/** Explorer special function key.
 * Used to launch a browser application. */
KEYCODE_EXPLORER = 64;
/** Envelope special function key.
 * Used to launch a mail application. */
KEYCODE_ENVELOPE = 65;
/** Enter key. */
KEYCODE_ENTER = 66;
/** Backspace key.
 * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */
KEYCODE_DEL = 67;
/** '`' (backtick) key. */
KEYCODE_GRAVE = 68;
/** '-'. */
KEYCODE_MINUS = 69;
/** '=' key. */
KEYCODE_EQUALS = 70;
/** '[' key. */
KEYCODE_LEFT_BRACKET = 71;
/** ']' key. */
KEYCODE_RIGHT_BRACKET = 72;
/** '\' key. */
KEYCODE_BACKSLASH = 73;
/** ';' key. */
KEYCODE_SEMICOLON = 74;
/** ''' (apostrophe) key. */
KEYCODE_APOSTROPHE = 75;
/** '/' key. */
KEYCODE_SLASH = 76;
/** '@' key. */
KEYCODE_AT = 77;
/** Number modifier key.
 * Used to enter numeric symbols.
 * This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is
 * interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */
KEYCODE_NUM = 78;
/** Headset Hook key.
 * Used to hang up calls and stop media. */
KEYCODE_HEADSETHOOK = 79;
/** Camera Focus key.
 * Used to focus the camera. */
KEYCODE_FOCUS = 80; // *Camera* focus
/** '+' key. */
KEYCODE_PLUS = 81;
/** Menu key. */
KEYCODE_MENU = 82;
/** Notification key. */
KEYCODE_NOTIFICATION = 83;
/** Search key. */
KEYCODE_SEARCH = 84;
/** Play/Pause media key. */
KEYCODE_MEDIA_PLAY_PAUSE= 85;
/** Stop media key. */
KEYCODE_MEDIA_STOP = 86;
/** Play Next media key. */
KEYCODE_MEDIA_NEXT = 87;
/** Play Previous media key. */
KEYCODE_MEDIA_PREVIOUS = 88;
/** Rewind media key. */
KEYCODE_MEDIA_REWIND = 89;
/** Fast Forward media key. */
KEYCODE_MEDIA_FAST_FORWARD = 90;
/** Mute key.
 * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */
KEYCODE_MUTE = 91;
/** Page Up key. */
KEYCODE_PAGE_UP = 92;
/** Page Down key. */
KEYCODE_PAGE_DOWN = 93;
/** Picture Symbols modifier key.
 * Used to switch symbol sets (Emoji, Kao-moji). */
KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji)
/** Switch Charset modifier key.
 * Used to switch character sets (Kanji, Katakana). */
KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana)
/** A Button key.
 * On a game controller, the A button should be either the button labeled A
 * or the first button on the bottom row of controller buttons. */
KEYCODE_BUTTON_A = 96;
/** B Button key.
 * On a game controller, the B button should be either the button labeled B
 * or the second button on the bottom row of controller buttons. */
KEYCODE_BUTTON_B = 97;
/** C Button key.
 * On a game controller, the C button should be either the button labeled C
 * or the third button on the bottom row of controller buttons. */
KEYCODE_BUTTON_C = 98;
/** X Button key.
 * On a game controller, the X button should be either the button labeled X
 * or the first button on the upper row of controller buttons. */
KEYCODE_BUTTON_X = 99;
/** Y Button key.
 * On a game controller, the Y button should be either the button labeled Y
 * or the second button on the upper row of controller buttons. */
KEYCODE_BUTTON_Y = 100;
/** Z Button key.
 * On a game controller, the Z button should be either the button labeled Z
 * or the third button on the upper row of controller buttons. */
KEYCODE_BUTTON_Z = 101;
/** L1 Button key.
 * On a game controller, the L1 button should be either the button labeled L1 (or L)
 * or the top left trigger button. */
KEYCODE_BUTTON_L1 = 102;
/** R1 Button key.
 * On a game controller, the R1 button should be either the button labeled R1 (or R)
 * or the top right trigger button. */
KEYCODE_BUTTON_R1 = 103;
/** L2 Button key.
 * On a game controller, the L2 button should be either the button labeled L2
 * or the bottom left trigger button. */
KEYCODE_BUTTON_L2 = 104;
/** R2 Button key.
 * On a game controller, the R2 button should be either the button labeled R2
 * or the bottom right trigger button. */
KEYCODE_BUTTON_R2 = 105;
/** Left Thumb Button key.
 * On a game controller, the left thumb button indicates that the left (or only)
 * joystick is pressed. */
KEYCODE_BUTTON_THUMBL = 106;
/** Right Thumb Button key.
 * On a game controller, the right thumb button indicates that the right
 * joystick is pressed. */
KEYCODE_BUTTON_THUMBR = 107;
/** Start Button key.
 * On a game controller, the button labeled Start. */
KEYCODE_BUTTON_START = 108;
/** Select Button key.
 * On a game controller, the button labeled Select. */
KEYCODE_BUTTON_SELECT = 109;
/** Mode Button key.
 * On a game controller, the button labeled Mode. */
KEYCODE_BUTTON_MODE = 110;
/** Escape key. */
KEYCODE_ESCAPE = 111;
/** Forward Delete key.
 * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */
KEYCODE_FORWARD_DEL = 112;
/** Left Control modifier key. */
KEYCODE_CTRL_LEFT = 113;
/** Right Control modifier key. */
KEYCODE_CTRL_RIGHT = 114;
/** Caps Lock key. */
KEYCODE_CAPS_LOCK = 115;
/** Scroll Lock key. */
KEYCODE_SCROLL_LOCK = 116;
/** Left Meta modifier key. */
KEYCODE_META_LEFT = 117;
/** Right Meta modifier key. */
KEYCODE_META_RIGHT = 118;
/** Function modifier key. */
KEYCODE_FUNCTION = 119;
/** System Request / Print Screen key. */
KEYCODE_SYSRQ = 120;
/** Break / Pause key. */
KEYCODE_BREAK = 121;
/** Home Movement key.
 * Used for scrolling or moving the cursor around to the start of a line
 * or to the top of a list. */
KEYCODE_MOVE_HOME = 122;
/** End Movement key.
 * Used for scrolling or moving the cursor around to the end of a line
 * or to the bottom of a list. */
KEYCODE_MOVE_END = 123;
/** Insert key.
 * Toggles insert / overwrite edit mode. */
KEYCODE_INSERT = 124;
/** Forward key.
 * Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */
KEYCODE_FORWARD = 125;
/** Play media key. */
KEYCODE_MEDIA_PLAY = 126;
/** Pause media key. */
KEYCODE_MEDIA_PAUSE = 127;
/** Close media key.
 * May be used to close a CD tray, for example. */
KEYCODE_MEDIA_CLOSE = 128;
/** Eject media key.
 * May be used to eject a CD tray, for example. */
KEYCODE_MEDIA_EJECT = 129;
/** Record media key. */
KEYCODE_MEDIA_RECORD = 130;
/** F1 key. */
KEYCODE_F1 = 131;
/** F2 key. */
KEYCODE_F2 = 132;
/** F3 key. */
KEYCODE_F3 = 133;
/** F4 key. */
KEYCODE_F4 = 134;
/** F5 key. */
KEYCODE_F5 = 135;
/** F6 key. */
KEYCODE_F6 = 136;
/** F7 key. */
KEYCODE_F7 = 137;
/** F8 key. */
KEYCODE_F8 = 138;
/** F9 key. */
KEYCODE_F9 = 139;
/** F10 key. */
KEYCODE_F10 = 140;
/** F11 key. */
KEYCODE_F11 = 141;
/** F12 key. */
KEYCODE_F12 = 142;
/** Num Lock key.
 * This is the Num Lock key; it is different from {@link #KEYCODE_NUM}.
 * This key alters the behavior of other keys on the numeric keypad. */
KEYCODE_NUM_LOCK = 143;
/** Numeric keypad '0' key. */
KEYCODE_NUMPAD_0 = 144;
/** Numeric keypad '1' key. */
KEYCODE_NUMPAD_1 = 145;
/** Numeric keypad '2' key. */
KEYCODE_NUMPAD_2 = 146;
/** Numeric keypad '3' key. */
KEYCODE_NUMPAD_3 = 147;
/** Numeric keypad '4' key. */
KEYCODE_NUMPAD_4 = 148;
/** Numeric keypad '5' key. */
KEYCODE_NUMPAD_5 = 149;
/** Numeric keypad '6' key. */
KEYCODE_NUMPAD_6 = 150;
/** Numeric keypad '7' key. */
KEYCODE_NUMPAD_7 = 151;
/** Numeric keypad '8' key. */
KEYCODE_NUMPAD_8 = 152;
/** Numeric keypad '9' key. */
KEYCODE_NUMPAD_9 = 153;
/** Numeric keypad '/' key (for division). */
KEYCODE_NUMPAD_DIVIDE = 154;
/** Numeric keypad '*' key (for multiplication). */
KEYCODE_NUMPAD_MULTIPLY = 155;
/** Numeric keypad '-' key (for subtraction). */
KEYCODE_NUMPAD_SUBTRACT = 156;
/** Numeric keypad '+' key (for addition). */
KEYCODE_NUMPAD_ADD = 157;
/** Numeric keypad '.' key (for decimals or digit grouping). */
KEYCODE_NUMPAD_DOT = 158;
/** Numeric keypad ',' key (for decimals or digit grouping). */
KEYCODE_NUMPAD_COMMA = 159;
/** Numeric keypad Enter key. */
KEYCODE_NUMPAD_ENTER = 160;
/** Numeric keypad '=' key. */
KEYCODE_NUMPAD_EQUALS = 161;
/** Numeric keypad '(' key. */
KEYCODE_NUMPAD_LEFT_PAREN = 162;
/** Numeric keypad ')' key. */
KEYCODE_NUMPAD_RIGHT_PAREN = 163;
/** Volume Mute key.
 * Mutes the speaker, unlike {@link #KEYCODE_MUTE}.
 * This key should normally be implemented as a toggle such that the first press
 * mutes the speaker and the second press restores the original volume. */
KEYCODE_VOLUME_MUTE = 164;
/** Info key.
 * Common on TV remotes to show additional information related to what is
 * currently being viewed. */
KEYCODE_INFO = 165;
/** Channel up key.
 * On TV remotes, increments the television channel. */
KEYCODE_CHANNEL_UP = 166;
/** Channel down key.
 * On TV remotes, decrements the television channel. */
KEYCODE_CHANNEL_DOWN = 167;
/** Zoom in key. */
KEYCODE_ZOOM_IN = 168;
/** Zoom out key. */
KEYCODE_ZOOM_OUT = 169;
/** TV key.
 * On TV remotes, switches to viewing live TV. */
KEYCODE_TV = 170;
/** Window key.
 * On TV remotes, toggles picture-in-picture mode or other windowing functions. */
KEYCODE_WINDOW = 171;
/** Guide key.
 * On TV remotes, shows a programming guide. */
KEYCODE_GUIDE = 172;
/** DVR key.
 * On some TV remotes, switches to a DVR mode for recorded shows. */
KEYCODE_DVR = 173;
/** Bookmark key.
 * On some TV remotes, bookmarks content or web pages. */
KEYCODE_BOOKMARK = 174;
/** Toggle captions key.
 * Switches the mode for closed-captioning text, for example during television shows. */
KEYCODE_CAPTIONS = 175;
/** Settings key.
 * Starts the system settings activity. */
KEYCODE_SETTINGS = 176;
/** TV power key.
 * On TV remotes, toggles the power on a television screen. */
KEYCODE_TV_POWER = 177;
/** TV input key.
 * On TV remotes, switches the input on a television screen. */
KEYCODE_TV_INPUT = 178;
/** Set-top-box power key.
 * On TV remotes, toggles the power on an external Set-top-box. */
KEYCODE_STB_POWER = 179;
/** Set-top-box input key.
 * On TV remotes, switches the input mode on an external Set-top-box. */
KEYCODE_STB_INPUT = 180;
/** A/V Receiver power key.
 * On TV remotes, toggles the power on an external A/V Receiver. */
KEYCODE_AVR_POWER = 181;
/** A/V Receiver input key.
 * On TV remotes, switches the input mode on an external A/V Receiver. */
KEYCODE_AVR_INPUT = 182;
/** Red "programmable" key.
 * On TV remotes, acts as a contextual/programmable key. */
KEYCODE_PROG_RED = 183;
/** Green "programmable" key.
 * On TV remotes, actsas a contextual/programmable key. */
KEYCODE_PROG_GREEN = 184;
/** Yellow "programmable" key.
 * On TV remotes, acts as a contextual/programmable key. */
KEYCODE_PROG_YELLOW = 185;
/** Blue "programmable" key.
 * On TV remotes, acts as a contextual/programmable key. */
KEYCODE_PROG_BLUE = 186;
/** App switch key.
 * Should bring up the application switcher dialog. */
KEYCODE_APP_SWITCH = 187;
/** Generic Game Pad Button #1.*/
KEYCODE_BUTTON_1 = 188;
/** Generic Game Pad Button #2.*/
KEYCODE_BUTTON_2 = 189;
/** Generic Game Pad Button #3.*/
KEYCODE_BUTTON_3 = 190;
/** Generic Game Pad Button #4.*/
KEYCODE_BUTTON_4 = 191;
/** Generic Game Pad Button #5.*/
KEYCODE_BUTTON_5 = 192;
/** Generic Game Pad Button #6.*/
KEYCODE_BUTTON_6 = 193;
/** Generic Game Pad Button #7.*/
KEYCODE_BUTTON_7 = 194;
/** Generic Game Pad Button #8.*/
KEYCODE_BUTTON_8 = 195;
/** Generic Game Pad Button #9.*/
KEYCODE_BUTTON_9 = 196;
/** Generic Game Pad Button #10.*/
KEYCODE_BUTTON_10 = 197;
/** Generic Game Pad Button #11.*/
KEYCODE_BUTTON_11 = 198;
/** Generic Game Pad Button #12.*/
KEYCODE_BUTTON_12 = 199;
/** Generic Game Pad Button #13.*/
KEYCODE_BUTTON_13 = 200;
/** Generic Game Pad Button #14.*/
KEYCODE_BUTTON_14 = 201;
/** Generic Game Pad Button #15.*/
KEYCODE_BUTTON_15 = 202;
/** Generic Game Pad Button #16.*/
KEYCODE_BUTTON_16 = 203;
/** Language Switch key.
 * Toggles the current input language such as switching between English and Japanese on
 * a QWERTY keyboard. On some devices, the same function may be performed by
 * pressing Shift+Spacebar. */
KEYCODE_LANGUAGE_SWITCH = 204;
/** Manner Mode key.
 * Toggles silent or vibrate mode on and off to make the device behave more politely
 * in certain settings such as on a crowded train. On some devices, the key may only
 * operate when long-pressed. */
KEYCODE_MANNER_MODE = 205;
/** 3D Mode key.
 * Toggles the display between 2D and 3D mode. */
KEYCODE_3D_MODE = 206;
/** Contacts special function key.
 * Used to launch an address book application. */
KEYCODE_CONTACTS = 207;
/** Calendar special function key.
 * Used to launch a calendar application. */
KEYCODE_CALENDAR = 208;
/** Music special function key.
 * Used to launch a music player application. */
KEYCODE_MUSIC = 209;
/** Calculator special function key.
 * Used to launch a calculator application. */
KEYCODE_CALCULATOR = 210;
/** Japanese full-width / half-width key. */
KEYCODE_ZENKAKU_HANKAKU = 211;
/** Japanese alphanumeric key. */
KEYCODE_EISU = 212;
/** Japanese non-conversion key. */
KEYCODE_MUHENKAN = 213;
/** Japanese conversion key. */
KEYCODE_HENKAN = 214;
/** Japanese katakana / hiragana key. */
KEYCODE_KATAKANA_HIRAGANA = 215;
/** Japanese Yen key. */
KEYCODE_YEN = 216;
/** Japanese Ro key. */
KEYCODE_RO = 217;
/** Japanese kana key. */
KEYCODE_KANA = 218;
/** Assist key.
 * Launches the global assist activity. Not delivered to applications. */
KEYCODE_ASSIST = 219;
/** Brightness Down key.
 * Adjusts the screen brightness down. */
KEYCODE_BRIGHTNESS_DOWN = 220;
/** Brightness Up key.
 * Adjusts the screen brightness up. */
KEYCODE_BRIGHTNESS_UP = 221;
/** Audio Track key.
 * Switches the audio tracks. */
KEYCODE_MEDIA_AUDIO_TRACK = 222;
/** Sleep key.
 * Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it
 * has no effect if the device is already asleep. */
KEYCODE_SLEEP = 223;
/** Wakeup key.
 * Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it
 * has no effect if the device is already awake. */
KEYCODE_WAKEUP = 224;
/** Pairing key.
 * Initiates peripheral pairing mode. Useful for pairing remote control
 * devices or game controllers, especially if no other input mode is
 * available. */
KEYCODE_PAIRING = 225;
/** Media Top Menu key.
 * Goes to the top of media menu. */
KEYCODE_MEDIA_TOP_MENU = 226;
/** '11' key. */
KEYCODE_11 = 227;
/** '12' key. */
KEYCODE_12 = 228;
/** Last Channel key.
 * Goes to the last viewed channel. */
KEYCODE_LAST_CHANNEL = 229;
/** TV data service key.
 * Displays data services like weather, sports. */
KEYCODE_TV_DATA_SERVICE = 230;
/** Voice Assist key.
 * Launches the global voice assist activity. Not delivered to applications. */
KEYCODE_VOICE_ASSIST = 231;
/** Radio key.
 * Toggles TV service / Radio service. */
KEYCODE_TV_RADIO_SERVICE = 232;
/** Teletext key.
 * Displays Teletext service. */
KEYCODE_TV_TELETEXT = 233;
/** Number entry key.
 * Initiates to enter multi-digit channel nubmber when each digit key is assigned
 * for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC
 * User Control Code. */
KEYCODE_TV_NUMBER_ENTRY = 234;
/** Analog Terrestrial key.
 * Switches to analog terrestrial broadcast service. */
KEYCODE_TV_TERRESTRIAL_ANALOG = 235;
/** Digital Terrestrial key.
 * Switches to digital terrestrial broadcast service. */
KEYCODE_TV_TERRESTRIAL_DIGITAL = 236;
/** Satellite key.
 * Switches to digital satellite broadcast service. */
KEYCODE_TV_SATELLITE = 237;
/** BS key.
 * Switches to BS digital satellite broadcasting service available in Japan. */
KEYCODE_TV_SATELLITE_BS = 238;
/** CS key.
 * Switches to CS digital satellite broadcasting service available in Japan. */
KEYCODE_TV_SATELLITE_CS = 239;
/** BS/CS key.
 * Toggles between BS and CS digital satellite services. */
KEYCODE_TV_SATELLITE_SERVICE = 240;
/** Toggle Network key.
 * Toggles selecting broacast services. */
KEYCODE_TV_NETWORK = 241;
/** Antenna/Cable key.
 * Toggles broadcast input source between antenna and cable. */
KEYCODE_TV_ANTENNA_CABLE = 242;
/** HDMI #1 key.
 * Switches to HDMI input #1. */
KEYCODE_TV_INPUT_HDMI_1 = 243;
/** HDMI #2 key.
 * Switches to HDMI input #2. */
KEYCODE_TV_INPUT_HDMI_2 = 244;
/** HDMI #3 key.
 * Switches to HDMI input #3. */
KEYCODE_TV_INPUT_HDMI_3 = 245;
/** HDMI #4 key.
 * Switches to HDMI input #4. */
KEYCODE_TV_INPUT_HDMI_4 = 246;
/** Composite #1 key.
 * Switches to composite video input #1. */
KEYCODE_TV_INPUT_COMPOSITE_1 = 247;
/** Composite #2 key.
 * Switches to composite video input #2. */
KEYCODE_TV_INPUT_COMPOSITE_2 = 248;
/** Component #1 key.
 * Switches to component video input #1. */
KEYCODE_TV_INPUT_COMPONENT_1 = 249;
/** Component #2 key.
 * Switches to component video input #2. */
KEYCODE_TV_INPUT_COMPONENT_2 = 250;
/** VGA #1 key.
 * Switches to VGA (analog RGB) input #1. */
KEYCODE_TV_INPUT_VGA_1 = 251;
/** Audio description key.
 * Toggles audio description off / on. */
KEYCODE_TV_AUDIO_DESCRIPTION = 252;
/** Audio description mixing volume up key.
 * Louden audio description volume as compared with normal audio volume. */
KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253;
/** Audio description mixing volume down key.
 * Lessen audio description volume as compared with normal audio volume. */
KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254;
/** Zoom mode key.
 * Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.) */
KEYCODE_TV_ZOOM_MODE = 255;
/** Contents menu key.
 * Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control
 * Code */
KEYCODE_TV_CONTENTS_MENU = 256;
/** Media context menu key.
 * Goes to the context menu of media contents. Corresponds to Media Context-sensitive
 * Menu (0x11) of CEC User Control Code. */
KEYCODE_TV_MEDIA_CONTEXT_MENU = 257;
/** Timer programming key.
 * Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of
 * CEC User Control Code. */
KEYCODE_TV_TIMER_PROGRAMMING = 258;
/** Help key. */
KEYCODE_HELP = 259;
/** Navigate to previous key.
 * Goes backward by one item in an ordered collection of items. */
KEYCODE_NAVIGATE_PREVIOUS = 260;
/** Navigate to next key.
 * Advances to the next item in an ordered collection of items. */
KEYCODE_NAVIGATE_NEXT = 261;
/** Navigate in key.
 * Activates the item that currently has focus or expands to the next level of a navigation
 * hierarchy. */
KEYCODE_NAVIGATE_IN = 262;
/** Navigate out key.
 * Backs out one level of a navigation hierarchy or collapses the item that currently has
 * focus. */
KEYCODE_NAVIGATE_OUT = 263;
/** Primary stem key for Wear
 * Main power/reset button on watch. */
KEYCODE_STEM_PRIMARY = 264;
/** Generic stem key 1 for Wear */
KEYCODE_STEM_1 = 265;
/** Generic stem key 2 for Wear */
KEYCODE_STEM_2 = 266;
/** Generic stem key 3 for Wear */
KEYCODE_STEM_3 = 267;
/** Directional Pad Up-Left */
KEYCODE_DPAD_UP_LEFT = 268;
/** Directional Pad Down-Left */
KEYCODE_DPAD_DOWN_LEFT = 269;
/** Directional Pad Up-Right */
KEYCODE_DPAD_UP_RIGHT = 270;
/** Directional Pad Down-Right */
KEYCODE_DPAD_DOWN_RIGHT = 271;
/** Skip forward media key. */
KEYCODE_MEDIA_SKIP_FORWARD = 272;
/** Skip backward media key. */
KEYCODE_MEDIA_SKIP_BACKWARD = 273;
/** Step forward media key.
 * Steps media forward, one frame at a time. */
KEYCODE_MEDIA_STEP_FORWARD = 274;
/** Step backward media key.
 * Steps media backward, one frame at a time. */
KEYCODE_MEDIA_STEP_BACKWARD = 275;
/** put device to sleep unless a wakelock is held. */
KEYCODE_SOFT_SLEEP = 276;
/** Cut key. */
KEYCODE_CUT = 277;
/** Copy key. */
KEYCODE_COPY = 278;
/** Paste key. */
KEYCODE_PASTE = 279;
/** Consumed by the system for navigation up */
KEYCODE_SYSTEM_NAVIGATION_UP = 280;
/** Consumed by the system for navigation down */
KEYCODE_SYSTEM_NAVIGATION_DOWN = 281;
/** Consumed by the system for navigation left*/
KEYCODE_SYSTEM_NAVIGATION_LEFT = 282;
/** Consumed by the system for navigation right */
KEYCODE_SYSTEM_NAVIGATION_RIGHT = 283;

  /** Key code constant: Show all apps */
public static final int KEYCODE_ALL_APPS = 284;
/** Key code constant: Refresh key. */
public static final int KEYCODE_REFRESH = 285;
/** Key code constant: Thumbs up key. Apps can use this to let user upvote content. */
public static final int KEYCODE_THUMBS_UP = 286;
/** Key code constant: Thumbs down key. Apps can use this to let user downvote content. */
public static final int KEYCODE_THUMBS_DOWN = 287;

###Notes

  • Currently the last key code is KEYCODE_SYSTEM_NAVIGATION_RIGHT, which is 283 (but check the source code to make sure this is still true). So you could loop through them like this:

      for (int keyCode = 0; keyCode <= 287; keyCode++) {
    
      }
    
  • Most input to EditText (or a custom view that accepts keyboard input) from an Input Method Editor (IME) is done using an Input Connection, so many key codes are not sent at all in this case. See this answer.

Mehul Boghra
  • 202
  • 3
  • 11
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • I'm creating a custom Keyboard for Spanish users, but I didn't find the exact *keyCode* to capture the Ñ key (N + tilde). I using the unicode character but doesn't work either. I using the reference from android source without success `https://source.android.com/devices/input/key-character-map-files` . Any tips for solve this problem? This is my code Any help would be appreciated –  Apr 06 '18 at 19:05
  • 1
    @MartínDaniel, Unicode characters need to be escaped with "\" as in `\\u0303`. If you need to use multiple Unicode characters together then you would use [`keyOutputText`](https://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html#attr_android:keyOutputText) rather than [`codes`](https://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html#attr_android:codes). Also, the `~` combining diacritical mark should go after the `n`, not before it. There is also `\\u00D1` and `\\u00F1` if you want to just use single Unicode characters. – Suragch Apr 07 '18 at 00:13
  • Thanks @Suragch `keyOutputText` is the parameter that I need. –  Apr 10 '18 at 15:55
  • Saracgh I wonder if I could pass these constants as keycode values in the xml file rather than raw integers. –  May 27 '19 at 07:11
  • @JaveneCPPMcGowan, I'm not sure if they are defined anywhere in XML, though I suppose you could define them yourself. I've only used them in code. – Suragch May 27 '19 at 14:50
  • saracgh i am writing this with my custom keyboard; but a key giving me real big trouble is enter/return. I implement it by sending KeyEvent; but in a text editor it doesnt newline. on firefox it triggers input but on chrome it does nothing. it also does nothing as i type this comment. how can i implement enter key so that it triggers input and also makes a newline appropriately. –  May 28 '19 at 02:36
  • @JaveneCPPMcGowan, I actually noticed that that was a bug with one of the main keyboard apps I published. I haven't had time to work on it recently. Would you mind asking a new Stack Overflow question about that and then link back to the question here? I would like to know the answer, too. – Suragch May 28 '19 at 02:46
  • Saragch so I tried changing Event type from KeyEvent.ACTION_DOWN for every special key case{enter,up,down,left,right,del,...}, to KeyEvent.ACTION_UP for enter key. This allowed newline in my text editor and triggered search in chrome. But stopped responding in Firefox. Obviously text editor implimentors are implementing events differently; except for directional keys. So as an IME implimentor, instead of only implimenting onKey() we must impliment onPress(), onRelease(), with the appropriate event type. –  May 28 '19 at 03:46
  • Saragch so I implimented it. onKey() checks for every key press; ignores enter key. onPress() and onRelease() handles only enter key. Both of them handle enter key, so that enter may be ignored on one case but not the other case. –  May 28 '19 at 04:43
  • @MartínDaniel use 241 as a decimal value for Ñ. – Kifayat Ullah Jan 27 '20 at 19:28
18

Keyboard(BT) commands can be passed through command prompt

open command prompt and write "adb shell input keyevent keycode"

examples:-

for "enter" write
adb shell input keyevent 23

up
adb shell input keyevent 19

down
adb shell input keyevent 20

left
adb shell input keyevent 21

right
adb shell input keyevent 22

keycode List:

0 -->  "KEYCODE_0" 
1 -->  "KEYCODE_SOFT_LEFT" 
2 -->  "KEYCODE_SOFT_RIGHT" 
3 -->  "KEYCODE_HOME" 
4 -->  "KEYCODE_BACK" 
5 -->  "KEYCODE_CALL" 
6 -->  "KEYCODE_ENDCALL" 
7 -->  "KEYCODE_0" 
8 -->  "KEYCODE_1" 
9 -->  "KEYCODE_2" 
10 -->  "KEYCODE_3" 
11 -->  "KEYCODE_4" 
12 -->  "KEYCODE_5" 
13 -->  "KEYCODE_6" 
14 -->  "KEYCODE_7" 
15 -->  "KEYCODE_8" 
16 -->  "KEYCODE_9" 
17 -->  "KEYCODE_STAR" 
18 -->  "KEYCODE_POUND" 
19 -->  "KEYCODE_DPAD_UP" 
20 -->  "KEYCODE_DPAD_DOWN" 
21 -->  "KEYCODE_DPAD_LEFT" 
22 -->  "KEYCODE_DPAD_RIGHT" 
23 -->  "KEYCODE_DPAD_CENTER" 
24 -->  "KEYCODE_VOLUME_UP" 
25 -->  "KEYCODE_VOLUME_DOWN" 
26 -->  "KEYCODE_POWER" 
27 -->  "KEYCODE_CAMERA" 
28 -->  "KEYCODE_CLEAR" 
29 -->  "KEYCODE_A" 
30 -->  "KEYCODE_B" 
31 -->  "KEYCODE_C" 
32 -->  "KEYCODE_D" 
33 -->  "KEYCODE_E" 
34 -->  "KEYCODE_F" 
35 -->  "KEYCODE_G" 
36 -->  "KEYCODE_H" 
37 -->  "KEYCODE_I" 
38 -->  "KEYCODE_J" 
39 -->  "KEYCODE_K" 
40 -->  "KEYCODE_L" 
41 -->  "KEYCODE_M" 
42 -->  "KEYCODE_N" 
43 -->  "KEYCODE_O" 
44 -->  "KEYCODE_P" 
45 -->  "KEYCODE_Q" 
46 -->  "KEYCODE_R" 
47 -->  "KEYCODE_S" 
48 -->  "KEYCODE_T" 
49 -->  "KEYCODE_U" 
50 -->  "KEYCODE_V" 
51 -->  "KEYCODE_W" 
52 -->  "KEYCODE_X" 
53 -->  "KEYCODE_Y" 
54 -->  "KEYCODE_Z" 
55 -->  "KEYCODE_COMMA" 
56 -->  "KEYCODE_PERIOD" 
57 -->  "KEYCODE_ALT_LEFT" 
58 -->  "KEYCODE_ALT_RIGHT" 
59 -->  "KEYCODE_SHIFT_LEFT" 
60 -->  "KEYCODE_SHIFT_RIGHT" 
61 -->  "KEYCODE_TAB" 
62 -->  "KEYCODE_SPACE" 
63 -->  "KEYCODE_SYM" 
64 -->  "KEYCODE_EXPLORER" 
65 -->  "KEYCODE_ENVELOPE" 
66 -->  "KEYCODE_ENTER" 
67 -->  "KEYCODE_DEL" 
68 -->  "KEYCODE_GRAVE" 
69 -->  "KEYCODE_MINUS" 
70 -->  "KEYCODE_EQUALS" 
71 -->  "KEYCODE_LEFT_BRACKET" 
72 -->  "KEYCODE_RIGHT_BRACKET" 
73 -->  "KEYCODE_BACKSLASH" 
74 -->  "KEYCODE_SEMICOLON" 
75 -->  "KEYCODE_APOSTROPHE" 
76 -->  "KEYCODE_SLASH" 
77 -->  "KEYCODE_AT" 
78 -->  "KEYCODE_NUM" 
79 -->  "KEYCODE_HEADSETHOOK" 
80 -->  "KEYCODE_FOCUS" 
81 -->  "KEYCODE_PLUS" 
82 -->  "KEYCODE_MENU" 
83 -->  "KEYCODE_NOTIFICATION" 
84 -->  "KEYCODE_SEARCH" 
85 -->  "KEYCODE_MEDIA_PLAY_PAUSE"
86 -->  "KEYCODE_MEDIA_STOP"
87 -->  "KEYCODE_MEDIA_NEXT"
88 -->  "KEYCODE_MEDIA_PREVIOUS"
89 -->  "KEYCODE_MEDIA_REWIND"
90 -->  "KEYCODE_MEDIA_FAST_FORWARD"
91 -->  "KEYCODE_MUTE"
92 -->  "KEYCODE_PAGE_UP"
93 -->  "KEYCODE_PAGE_DOWN"
94 -->  "KEYCODE_PICTSYMBOLS"
...
122 -->  "KEYCODE_MOVE_HOME"
123 -->  "KEYCODE_MOVE_END"
Gorav Sharma
  • 410
  • 5
  • 7
14

Scroll down to "HID Keyboard and Keypad Page"

this page indeed has lots of information

Keyboard Devices Code Tables

Bruno Monteiro
  • 4,153
  • 5
  • 29
  • 48
Abbas Elmas
  • 422
  • 6
  • 16
7

OK, I found it finally.

Key Event This document lists volume up as 24. The key code I was looking for is Alt-Menu and apparently it executes regardless of having the key intercepted.

Thanks to those those who took the time to reply.

Allen Edwards
  • 1,488
  • 1
  • 27
  • 44
4

I had to make my own JSON file to loop on the key codes for android devices

{
    "UNKNOWN": "0",
    "SOFT_LEFT": "1",
    "SOFT_RIGHT": "2",
    "HOME": "3",
    "BACK": "4",
    "CALL": "5",
    "ENDCALL": "6",
    "0": "7",
    "1": "8",
    "2": "9",
    "3": "10",
    "4": "11",
    "5": "12",
    "6": "13",
    "7": "14",
    "8": "15",
    "9": "16",
    "STAR": "17",
    "POUND": "18",
    "DPAD_UP": "19",
    "DPAD_DOWN": "20",
    "DPAD_LEFT": "21",
    "DPAD_RIGHT": "22",
    "DPAD_CENTER": "23",
    "VOLUME_UP": "24",
    "VOLUME_DOWN": "25",
    "POWER": "26",
    "CAMERA": "27",
    "CLEAR": "28",
    "A": "29",
    "B": "30",
    "C": "31",
    "D": "32",
    "E": "33",
    "F": "34",
    "G": "35",
    "H": "36",
    "I": "37",
    "J": "38",
    "K": "39",
    "L": "40",
    "M": "41",
    "N": "42",
    "O": "43",
    "P": "44",
    "Q": "45",
    "R": "46",
    "S": "47",
    "T": "48",
    "U": "49",
    "V": "50",
    "W": "51",
    "X": "52",
    "Y": "53",
    "Z": "54",
    "COMMA": "55",
    "PERIOD": "56",
    "ALT_LEFT": "57",
    "ALT_RIGHT": "58",
    "SHIFT_LEFT": "59",
    "SHIFT_RIGHT": "60",
    "TAB": "61",
    "SPACE": "62",
    "SYM": "63",
    "EXPLORER": "64",
    "ENVELOPE": "65",
    "ENTER": "66",
    "DEL": "67",
    "GRAVE": "68",
    "MINUS": "69",
    "EQUALS": "70",
    "LEFT_BRACKET": "71",
    "RIGHT_BRACKET": "72",
    "BACKSLASH": "73",
    "SEMICOLON": "74",
    "APOSTROPHE": "75",
    "SLASH": "76",
    "AT": "77",
    "NUM": "78",
    "HEADSETHOOK": "79",
    "PLUS": "81",
    "MENU": "82",
    "NOTIFICATION": "83",
    "SEARCH": "84",
    "MEDIA_PLAY_PAUSE": "85",
    "MEDIA_STOP": "86",
    "MEDIA_NEXT": "87",
    "MEDIA_PREVIOUS": "88",
    "MEDIA_REWIND": "89",
    "MEDIA_FAST_FORWARD": "90",
    "MUTE": "91",
    "PAGE_UP": "92",
    "PAGE_DOWN": "93",
    "BUTTON_A": "96",
    "BUTTON_B": "97",
    "BUTTON_C": "98",
    "BUTTON_X": "99",
    "BUTTON_Y": "100",
    "BUTTON_Z": "101",
    "BUTTON_L1": "102",
    "BUTTON_R1": "103",
    "BUTTON_L2": "104",
    "BUTTON_R2": "105",
    "BUTTON_THUMBL": "106",
    "BUTTON_THUMBR": "107",
    "BUTTON_START": "108",
    "BUTTON_SELECT": "109",
    "BUTTON_MODE": "110",
    "ESCAPE": "111",
    "FORWARD_DEL": "112",
    "CTRL_LEFT": "113",
    "CTRL_RIGHT": "114",
    "CAPS_LOCK": "115",
    "SCROLL_LOCK": "116",
    "META_LEFT": "117",
    "META_RIGHT": "118",
    "FUNCTION": "119",
    "SYSRQ": "120",
    "BREAK": "121",
    "MOVE_HOME": "122",
    "MOVE_END": "123",
    "INSERT": "124",
    "FORWARD": "125",
    "MEDIA_PLAY": "126",
    "MEDIA_PAUSE": "127",
    "MEDIA_CLOSE": "128",
    "MEDIA_EJECT": "129",
    "MEDIA_RECORD": "130",
    "F1": "131",
    "F2": "132",
    "F3": "133",
    "F4": "134",
    "F5": "135",
    "F6": "136",
    "F7": "137",
    "F8": "138",
    "F9": "139",
    "F10": "140",
    "F11": "141",
    "F12": "142",
    "NUM_LOCK": "143",
    "NUMPAD_0": "144",
    "NUMPAD_1": "145",
    "NUMPAD_2": "146",
    "NUMPAD_3": "147",
    "NUMPAD_4": "148",
    "NUMPAD_5": "149",
    "NUMPAD_6": "150",
    "NUMPAD_7": "151",
    "NUMPAD_8": "152",
    "NUMPAD_9": "153",
    "NUMPAD_DIVIDE": "154",
    "NUMPAD_MULTIPLY": "155",
    "NUMPAD_SUBTRACT": "156",
    "NUMPAD_ADD": "157",
    "NUMPAD_DOT": "158",
    "NUMPAD_COMMA": "159",
    "NUMPAD_ENTER": "160",
    "NUMPAD_EQUALS": "161",
    "NUMPAD_LEFT_PAREN": "162",
    "NUMPAD_RIGHT_PAREN": "163",
    "VOLUME_MUTE": "164",
    "INFO": "165",
    "CHANNEL_UP": "166",
    "CHANNEL_DOWN": "167",
    "ZOOM_IN": "168",
    "ZOOM_OUT": "169",
    "TV": "170",
    "WINDOW": "171",
    "GUIDE": "172",
    "DVR": "173",
    "BOOKMARK": "174",
    "CAPTIONS": "175",
    "SETTINGS": "176",
    "TV_POWER": "177",
    "TV_INPUT": "178",
    "STB_POWER": "179",
    "STB_INPUT": "180",
    "AVR_POWER": "181",
    "AVR_INPUT": "182",
    "PROG_RED": "183",
    "PROG_GREEN": "184",
    "PROG_YELLOW": "185",
    "PROG_BLUE": "186",
    "APP_SWITCH": "187",
    "BUTTON_1": "188",
    "BUTTON_2": "189",
    "BUTTON_3": "190",
    "BUTTON_4": "191",
    "BUTTON_5": "192",
    "BUTTON_6": "193",
    "BUTTON_7": "194",
    "BUTTON_8": "195",
    "BUTTON_9": "196",
    "BUTTON_10": "197",
    "BUTTON_11": "198",
    "BUTTON_12": "199",
    "BUTTON_13": "200",
    "BUTTON_14": "201",
    "BUTTON_15": "202",
    "BUTTON_16": "203",
    "LANGUAGE_SWITCH": "204",
    "MANNER_MODE": "205",
    "3D_MODE": "206",
    "CONTACTS": "207",
    "CALENDAR": "208",
    "MUSIC": "209",
    "CALCULATOR": "210",
    "ZENKAKU_HANKAKU": "211",
    "EISU": "212",
    "MUHENKAN": "213",
    "HENKAN": "214",
    "KATAKANA_HIRAGANA": "215",
    "YEN": "216",
    "RO": "217",
    "KANA": "218",
    "ASSIST": "219",
    "BRIGHTNESS_DOWN": "220",
    "BRIGHTNESS_UP": "221",
    "MEDIA_AUDIO_TRACK": "222",
    "SLEEP": "223",
    "WAKEUP": "224",
    "PAIRING": "225",
    "MEDIA_TOP_MENU": "226",
    "11": "227",
    "12": "228",
    "LAST_CHANNEL": "229",
    "TV_DATA_SERVICE": "230",
    "VOICE_ASSIST": "231",
    "TV_RADIO_SERVICE": "232",
    "TV_TELETEXT": "233",
    "TV_NUMBER_ENTRY": "234",
    "TV_TERRESTRIAL_ANALOG": "235",
    "TV_TERRESTRIAL_DIGITAL": "236",
    "TV_SATELLITE": "237",
    "TV_SATELLITE_BS": "238",
    "TV_SATELLITE_CS": "239",
    "TV_SATELLITE_SERVICE": "240",
    "TV_NETWORK": "241",
    "TV_ANTENNA_CABLE": "242",
    "TV_INPUT_HDMI_1": "243",
    "TV_INPUT_HDMI_2": "244",
    "TV_INPUT_HDMI_3": "245",
    "TV_INPUT_HDMI_4": "246",
    "TV_INPUT_COMPOSITE_1": "247",
    "TV_INPUT_COMPOSITE_2": "248",
    "TV_INPUT_COMPONENT_1": "249",
    "TV_INPUT_COMPONENT_2": "250",
    "TV_INPUT_VGA_1": "251",
    "TV_AUDIO_DESCRIPTION": "252",
    "TV_AUDIO_DESCRIPTION_MIX_UP": "253",
    "TV_AUDIO_DESCRIPTION_MIX_DOWN": "254",
    "TV_ZOOM_MODE": "255",
    "TV_CONTENTS_MENU": "256",
    "TV_MEDIA_CONTEXT_MENU": "257",
    "TV_TIMER_PROGRAMMING": "258",
    "HELP": "259",
    "NAVIGATE_PREVIOUS": "260",
    "NAVIGATE_NEXT": "261",
    "NAVIGATE_IN": "262",
    "NAVIGATE_OUT": "263",
    "STEM_PRIMARY": "264",
    "STEM_1": "265",
    "STEM_2": "266",
    "STEM_3": "267",
    "DPAD_UP_LEFT": "268",
    "DPAD_DOWN_LEFT": "269",
    "DPAD_UP_RIGHT": "270",
    "DPAD_DOWN_RIGHT": "271",
    "MEDIA_SKIP_FORWARD": "272",
    "MEDIA_SKIP_BACKWARD": "273",
    "MEDIA_STEP_FORWARD": "274",
    "MEDIA_STEP_BACKWARD": "275",
    "SOFT_SLEEP": "276",
    "CUT": "277",
    "COPY": "278",
    "PASTE": "279",
    "SYSTEM_NAVIGATION_UP": "280",
    "SYSTEM_NAVIGATION_DOWN": "281",
    "SYSTEM_NAVIGATION_LEFT": "282",
    "SYSTEM_NAVIGATION_RIGHT": "283",
    "KEYCODE_ALL_APPS": "284",
    "KEYCODE_REFRESH": "285",
    "KEYCODE_THUMBS_UP": "286",
    "KEYCODE_THUMBS_DOWN": "287"
}
ANUBIS
  • 666
  • 1
  • 9
  • 20
1

You can find a complete list of Key Codes and an explanation here: http://code.google.com/p/androhid/wiki/Keycodes

Tushar
  • 8,019
  • 31
  • 38
  • That list does not show 24 as volume up. My presenter has a volume up key and the key code generated is 24. I know that is the code for that key as I get that from my code. I also know 71 is "[" as when I hit the key that produces that in a text editor I get a "[". The reference above does not agree with this. – Allen Edwards Aug 01 '12 at 22:28
  • If you read the page, you'll see it explains that the key mappings are not the same across all devices. With an open platform like Android where you not only have many different devices, but also different uses (such as a presenter or a tablet), you're not going to find a comprehensive list of mappings. – Tushar Aug 01 '12 at 22:30
  • If I press the key that generates a 71 when I have a text editor open I get a "[" printed in the open document. This is just a text editor, nothing fancy, so I think this should be a simple translation. – Allen Edwards Aug 01 '12 at 22:34
1

This is so out of date, but in case someone googles this, I have the same issue and figured it out.

If you use KeyEvent Viewer, volume up has a code=24, but a scanCode of 115.

Now my USB controller, only has code=# and all scanCodes are 0. But my airmouse (Mele F10) has all keys with codes and scan codes, but the scancode is what you have to put in the .kl file.

Hope this helps someone out there.

Brian
  • 11
  • 1
1

Additionally, if you have the NDK installed, you can also find the listing in ${ndk_path}platforms\android-${api}\${architecture}\usr\include\android\keycodes.h.

I'm only mentioning it because I've found it simpler to navigate and read than the KeyEvent class or docs.

zyndor
  • 1,418
  • 3
  • 20
  • 36
0

The actual standard key-layout is found in /system/usr/keylayout/qwerty.kl within the Android running on the handset. And it is a generic keylayout also.

key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE

From the AOSP source it can be found in sdk/emulator/keymaps/qwerty.kl.

But bear in mind this, when the source gets compiled along with a device specific keylayout, that will override the standard layout instead so the mileage will vary depending on what the manufacturer has programmed into the keycode for the volume up/down buttons in your case!

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
  • My keylayout/qwerty.kl file has those codes (115 and 114) in it as well but when I press the volume-up key on either my tablet or my presenter and display the result of getKeyCode() I get a 24. There must be a reference somewhere either on the tablet itself or the internet that shows a 24 as a volume-up. – Allen Edwards Aug 01 '12 at 23:52
  • what is the manufacturer, make and model of your tablet and what version of android? – t0mm13b Aug 02 '12 at 00:04
  • It is a samsung galazy tab-2 running 4.04. I also have a Nexus-S also running 4.04 and get the same keycode() from it. My Nexus-One running 2.3.6 gives the same code. That is 4 devices (counting the presenter) all giving 24 as the volume up code. This has to be documented somewhere don't you think? – Allen Edwards Aug 02 '12 at 00:32
0

Here's an arraylist version for my JAVA friends Based on Shari Sharif's JSON answer

Couldn't paste full due to 30000 character limit on stack overflow

Full version: https://gist.github.com/omkar-tenkale/822bff6a19ad12a21bc2a2d24f6fc834

public static ArrayList<ArrayList<String>> getKeyEvents() {
        return new ArrayList<ArrayList<String>>() {
            {
                add(new ArrayList<String>() {{
                    add("UNKNOWN");
                    add("0");
                }});
                add(new ArrayList<String>() {{
                    add("SOFT_LEFT");
                    add("1");
                }});
                add(new ArrayList<String>() {{
                    add("SOFT_RIGHT");
                    add("2");
                }});
                add(new ArrayList<String>() {{
                    add("HOME");
                    add("3");
                }});
                add(new ArrayList<String>() {{
                    add("BACK");
                    add("4");
                }});
                add(new ArrayList<String>() {{
                    add("CALL");
                    add("5");
                }});
                add(new ArrayList<String>() {{
                    add("ENDCALL");
                    add("6");
                }});
                add(new ArrayList<String>() {{
                    add("0");
                    add("7");
                }});
                add(new ArrayList<String>() {{
                    add("1");
                    add("8");
                }});
                add(new ArrayList<String>() {{
                    add("2");
                    add("9");
                }});
                add(new ArrayList<String>() {{
                    add("3");
                    add("10");
                }});
                add(new ArrayList<String>() {{
                    add("4");
                    add("11");
                }});
                add(new ArrayList<String>() {{
                    add("5");
                    add("12");
                }});
                add(new ArrayList<String>() {{
                    add("6");
                    add("13");
                }});
                add(new ArrayList<String>() {{
                    add("7");
                    add("14");
                }});
                add(new ArrayList<String>() {{
                    add("8");
                    add("15");
                }});
                add(new ArrayList<String>() {{
                    add("9");
                    add("16");
                }});
                add(new ArrayList<String>() {{
                    add("STAR");
                    add("17");
                }});
                add(new ArrayList<String>() {{
                    add("POUND");
                    add("18");
                }});
                add(new ArrayList<String>() {{
                    add("DPAD_UP");
                    add("19");
                }});
                add(new ArrayList<String>() {{
                    add("DPAD_DOWN");
                    add("20");
                }});
                add(new ArrayList<String>() {{
                    add("DPAD_LEFT");
                    add("21");
                }});
                add(new ArrayList<String>() {{
                    add("DPAD_RIGHT");
                    add("22");
                }});
                add(new ArrayList<String>() {{
                    add("DPAD_CENTER");
                    add("23");
                }});
                add(new ArrayList<String>() {{
                    add("VOLUME_UP");
                    add("24");
                }});
                add(new ArrayList<String>() {{
                    add("VOLUME_DOWN");
                    add("25");
                }});
                add(new ArrayList<String>() {{
                    add("POWER");
                    add("26");
                }});
                add(new ArrayList<String>() {{
                    add("CAMERA");
                    add("27");
                }});
                add(new ArrayList<String>() {{
                    add("CLEAR");
                    add("28");
                }});
                add(new ArrayList<String>() {{
                    add("A");
                    add("29");
                }});
                add(new ArrayList<String>() {{
                    add("B");
                    add("30");
                }});
                add(new ArrayList<String>() {{
                    add("C");
                    add("31");
                }});
                add(new ArrayList<String>() {{
                    add("D");
                    add("32");
                }});
                add(new ArrayList<String>() {{
                    add("E");
                    add("33");
                }});
                add(new ArrayList<String>() {{
                    add("F");
                    add("34");
                }});
                add(new ArrayList<String>() {{
                    add("G");
                    add("35");
                }});
                add(new ArrayList<String>() {{
                    add("H");
                    add("36");
                }});
                add(new ArrayList<String>() {{
                    add("I");
                    add("37");
                }});
                add(new ArrayList<String>() {{
                    add("J");
                    add("38");
                }});
                add(new ArrayList<String>() {{
                    add("K");
                    add("39");
                }});
                add(new ArrayList<String>() {{
                    add("L");
                    add("40");
                }});
                add(new ArrayList<String>() {{
                    add("M");
                    add("41");
                }});
                add(new ArrayList<String>() {{
                    add("N");
                    add("42");
                }});
                add(new ArrayList<String>() {{
                    add("O");
                    add("43");
                }});
                add(new ArrayList<String>() {{
                    add("P");
                    add("44");
                }});
                add(new ArrayList<String>() {{
                    add("Q");
                    add("45");
                }});
                add(new ArrayList<String>() {{
                    add("R");
                    add("46");
                }});
                add(new ArrayList<String>() {{
                    add("S");
                    add("47");
                }});
                add(new ArrayList<String>() {{
                    add("T");
                    add("48");
                }});
                add(new ArrayList<String>() {{
                    add("U");
                    add("49");
                }});
                add(new ArrayList<String>() {{
                    add("V");
                    add("50");
                }});
                add(new ArrayList<String>() {{
                    add("W");
                    add("51");
                }});
                add(new ArrayList<String>() {{
                    add("X");
                    add("52");
                }});
                add(new ArrayList<String>() {{
                    add("Y");
                    add("53");
                }});
                add(new ArrayList<String>() {{
                    add("Z");
                    add("54");
                }});
                add(new ArrayList<String>() {{
                    add("COMMA");
                    add("55");
                }});
                add(new ArrayList<String>() {{
                    add("PERIOD");
                    add("56");
                }});
                add(new ArrayList<String>() {{
                    add("ALT_LEFT");
                    add("57");
                }});
                add(new ArrayList<String>() {{
                    add("ALT_RIGHT");
                    add("58");
                }});
                add(new ArrayList<String>() {{
                    add("SHIFT_LEFT");
                    add("59");
                }});
                add(new ArrayList<String>() {{
                    add("SHIFT_RIGHT");
                    add("60");
                }});
                add(new ArrayList<String>() {{
                    add("TAB");
                    add("61");
                }});
                add(new ArrayList<String>() {{
                    add("SPACE");
                    add("62");
                }});
                add(new ArrayList<String>() {{
                    add("SYM");
                    add("63");
                }});
                add(new ArrayList<String>() {{
                    add("EXPLORER");
                    add("64");
                }});
                add(new ArrayList<String>() {{
                    add("ENVELOPE");
                    add("65");
                }});
                add(new ArrayList<String>() {{
                    add("ENTER");
                    add("66");
                }});
                add(new ArrayList<String>() {{
                    add("DEL");
                    add("67");
                }});
                add(new ArrayList<String>() {{
                    add("GRAVE");
                    add("68");
                }});
                add(new ArrayList<String>() {{
                    add("MINUS");
                    add("69");
                }});
                add(new ArrayList<String>() {{
                    add("EQUALS");
                    add("70");
                }});
                add(new ArrayList<String>() {{
                    add("LEFT_BRACKET");
                    add("71");
                }});
                add(new ArrayList<String>() {{
                    add("RIGHT_BRACKET");
                    add("72");
                }});
                add(new ArrayList<String>() {{
                    add("BACKSLASH");
                    add("73");
                }});
                add(new ArrayList<String>() {{
                    add("SEMICOLON");
                    add("74");
                }});
                add(new ArrayList<String>() {{
                    add("APOSTROPHE");
                    add("75");
                }});
                add(new ArrayList<String>() {{
                    add("SLASH");
                    add("76");
                }});
                add(new ArrayList<String>() {{
                    add("AT");
                    add("77");
                }});
                add(new ArrayList<String>() {{
                    add("NUM");
                    add("78");
                }});
                add(new ArrayList<String>() {{
                    add("HEADSETHOOK");
                    add("79");
                }});
                add(new ArrayList<String>() {{
                    add("PLUS");
                    add("81");
                }});
                add(new ArrayList<String>() {{
                    add("MENU");
                    add("82");
                }});
                add(new ArrayList<String>() {{
                    add("NOTIFICATION");
                    add("83");
                }});
                add(new ArrayList<String>() {{
                    add("SEARCH");
                    add("84");
                }});
                add(new ArrayList<String>() {{
                    add("MEDIA_PLAY_PAUSE");
                    add("85");
                }});
                add(new ArrayList<String>() {{
                    add("MEDIA_STOP");
                    add("86");
                }});
                add(new ArrayList<String>() {{
                    add("MEDIA_NEXT");
                    add("87");
                }});
                add(new ArrayList<String>() {{
                    add("MEDIA_PREVIOUS");
                    add("88");
                }});
                add(new ArrayList<String>() {{
                    add("MEDIA_REWIND");
                    add("89");
                }});
                add(new ArrayList<String>() {{
                    add("MEDIA_FAST_FORWARD");
                    add("90");
                }});
                add(new ArrayList<String>() {{
                    add("MUTE");
                    add("91");
                }});
                add(new ArrayList<String>() {{
                    add("PAGE_UP");
                    add("92");
                }});
                add(new ArrayList<String>() {{
                    add("PAGE_DOWN");
                    add("93");
                }});
                add(new ArrayList<String>() {{
                    add("BUTTON_A");
                    add("96");
                }});
                add(new ArrayList<String>() {{
                    add("BUTTON_B");
                    add("97");
                }});
                add(new ArrayList<String>() {{
                    add("BUTTON_C");
                    add("98");
                }});
                add(new ArrayList<String>() {{
                    add("BUTTON_X");
                    add("99");
                }});
                add(new ArrayList<String>() {{
                    add("BUTTON_Y");
                    add("100");
                }});
Omkar T
  • 755
  • 8
  • 19
0

most of guys above seem missing meta key codes so I help you out with full list of keycodes on regex. It is based on the source which is clearly updated by day. You can choose export -> plain text -> then copy it. enter image description here

-1

They are ASCII dec codes. A full table can be found here.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
buill bogger
  • 9
  • 1
  • 5
  • 1
    despite some similarities they have different purpose and use. ASCII decimals are universal, keycode are not and have different values according to the language and platform. – elsadek Dec 30 '17 at 11:41