android KeyCode专题

 

相关的几个文件:

frameworks/base/data/keyboards/Generic.kl

# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Generic key layout file for full alphabetic US English PC style external keyboards.
#
# This file is intentionally very generic and is intended to support a broad rang of keyboards.
# Do not edit the generic key layout to support a specific keyboard; instead, create
# a new key layout file with the required keyboard configuration.
#

key 1     ESCAPE
key 2     1
key 3     2
key 4     3
key 5     4
key 6     5
key 7     6
key 8     7
key 9     8
key 10    9
key 11    0
key 12    MINUS
key 13    EQUALS
key 14    DEL
key 15    TAB
key 16    Q
key 17    W
key 18    E
key 19    R
key 20    T
key 21    Y
key 22    U
key 23    I
key 24    O
key 25    P
key 26    LEFT_BRACKET
key 27    RIGHT_BRACKET
key 28    ENTER
key 29    CTRL_LEFT
key 30    A
key 31    S
key 32    D
key 33    F
key 34    G
key 35    H
key 36    J
key 37    K
key 38    L
key 39    SEMICOLON
key 40    APOSTROPHE
key 41    GRAVE
key 42    SHIFT_LEFT
key 43    BACKSLASH
key 44    Z
key 45    X
key 46    C
key 47    V
key 48    B
key 49    N
key 50    M
key 51    COMMA
key 52    PERIOD
key 53    SLASH
key 54    SHIFT_RIGHT
key 55    NUMPAD_MULTIPLY
key 56    ALT_LEFT
key 57    SPACE
key 58    CAPS_LOCK
key 59    F1
key 60    F2
key 61    F3
key 62    F4
key 63    F5
key 64    F6
key 65    F7
key 66    F8
key 67    F9
key 68    F10
key 69    NUM_LOCK
key 70    SCROLL_LOCK
key 71    NUMPAD_7
key 72    NUMPAD_8
key 73    NUMPAD_9
key 74    NUMPAD_SUBTRACT
key 75    NUMPAD_4
key 76    NUMPAD_5
key 77    NUMPAD_6
key 78    NUMPAD_ADD
key 79    NUMPAD_1
key 80    NUMPAD_2
key 81    NUMPAD_3
key 82    NUMPAD_0
key 83    NUMPAD_DOT
# key 84 (undefined)
key 85    ZENKAKU_HANKAKU
key 86    BACKSLASH
key 87    F11
key 88    F12
key 89    RO
# key 90 "KEY_KATAKANA"
# key 91 "KEY_HIRAGANA"
key 92    HENKAN
key 93    KATAKANA_HIRAGANA
key 94    MUHENKAN
key 95    NUMPAD_COMMA
key 96    NUMPAD_ENTER
key 97    CTRL_RIGHT
key 98    NUMPAD_DIVIDE
key 99    SYSRQ
key 100   ALT_RIGHT
# key 101 "KEY_LINEFEED"
key 102   MOVE_HOME
key 103   DPAD_UP
key 104   PAGE_UP
key 105   DPAD_LEFT
key 106   DPAD_RIGHT
key 107   MOVE_END
key 108   DPAD_DOWN
key 109   PAGE_DOWN
key 110   INSERT
key 111   FORWARD_DEL
# key 112 "KEY_MACRO"
key 113   VOLUME_MUTE
key 114   VOLUME_DOWN
key 115   VOLUME_UP
key 116   POWER             WAKE
key 117   NUMPAD_EQUALS
# key 118 "KEY_KPPLUSMINUS"
key 119   BREAK
# key 120 (undefined)
key 121   NUMPAD_COMMA
key 122   KANA
key 123   EISU
key 124   YEN
key 125   META_LEFT
key 126   META_RIGHT
key 127   MENU              WAKE_DROPPED
key 128   MEDIA_STOP
# key 129 "KEY_AGAIN"
# key 130 "KEY_PROPS"
# key 131 "KEY_UNDO"
# key 132 "KEY_FRONT"
# key 133 "KEY_COPY"
# key 134 "KEY_OPEN"
# key 135 "KEY_PASTE"
# key 136 "KEY_FIND"
# key 137 "KEY_CUT"
# key 138 "KEY_HELP"
key 139   MENU              WAKE_DROPPED
key 140   CALCULATOR
# key 141 "KEY_SETUP"
key 142   POWER             WAKE
key 143   POWER             WAKE
# key 144 "KEY_FILE"
# key 145 "KEY_SENDFILE"
# key 146 "KEY_DELETEFILE"
# key 147 "KEY_XFER"
# key 148 "KEY_PROG1"
# key 149 "KEY_PROG2"
key 150   EXPLORER
# key 151 "KEY_MSDOS"
key 152   POWER             WAKE
# key 153 "KEY_DIRECTION"
# key 154 "KEY_CYCLEWINDOWS"
key 155   ENVELOPE
key 156   BOOKMARK
# key 157 "KEY_COMPUTER"
key 158   BACK              WAKE_DROPPED
key 159   FORWARD
key 160   MEDIA_CLOSE
key 161   MEDIA_EJECT
key 162   MEDIA_EJECT
key 163   MEDIA_NEXT
key 164   MEDIA_PLAY_PAUSE
key 165   MEDIA_PREVIOUS
key 166   MEDIA_STOP
key 167   MEDIA_RECORD
key 168   MEDIA_REWIND
key 169   CALL
# key 170 "KEY_ISO"
key 171   MUSIC
key 172   HOME
# key 173 "KEY_REFRESH"
# key 174 "KEY_EXIT"
# key 175 "KEY_MOVE"
# key 176 "KEY_EDIT"
key 177   PAGE_UP
key 178   PAGE_DOWN
key 179   NUMPAD_LEFT_PAREN
key 180   NUMPAD_RIGHT_PAREN
# key 181 "KEY_NEW"
# key 182 "KEY_REDO"
# key 183   F13
# key 184   F14
# key 185   F15
# key 186   F16
# key 187   F17
# key 188   F18
# key 189   F19
# key 190   F20
# key 191   F21
# key 192   F22
# key 193   F23
# key 194   F24
# key 195 (undefined)
# key 196 (undefined)
# key 197 (undefined)
# key 198 (undefined)
# key 199 (undefined)
key 200   MEDIA_PLAY
key 201   MEDIA_PAUSE
# key 202 "KEY_PROG3"
# key 203 "KEY_PROG4"
# key 204 (undefined)
# key 205 "KEY_SUSPEND"
# key 206 "KEY_CLOSE"
key 207   MEDIA_PLAY
key 208   MEDIA_FAST_FORWARD
# key 209 "KEY_BASSBOOST"
# key 210 "KEY_PRINT"
# key 211 "KEY_HP"
key 212   CAMERA
key 213   MUSIC
# key 214 "KEY_QUESTION"
key 215   ENVELOPE
# key 216 "KEY_CHAT"
key 217   SEARCH
# key 218 "KEY_CONNECT"
# key 219 "KEY_FINANCE"
# key 220 "KEY_SPORT"
# key 221 "KEY_SHOP"
# key 222 "KEY_ALTERASE"
# key 223 "KEY_CANCEL"
# key 224 "KEY_BRIGHTNESSDOWN"
# key 225 "KEY_BRIGHTNESSUP"
key 226   HEADSETHOOK

key 256   BUTTON_1
key 257   BUTTON_2
key 258   BUTTON_3
key 259   BUTTON_4
key 260   BUTTON_5
key 261   BUTTON_6
key 262   BUTTON_7
key 263   BUTTON_8
key 264   BUTTON_9
key 265   BUTTON_10
key 266   BUTTON_11
key 267   BUTTON_12
key 268   BUTTON_13
key 269   BUTTON_14
key 270   BUTTON_15
key 271   BUTTON_16

key 288   BUTTON_1
key 289   BUTTON_2
key 290   BUTTON_3
key 291   BUTTON_4
key 292   BUTTON_5
key 293   BUTTON_6
key 294   BUTTON_7
key 295   BUTTON_8
key 296   BUTTON_9
key 297   BUTTON_10
key 298   BUTTON_11
key 299   BUTTON_12
key 300   BUTTON_13
key 301   BUTTON_14
key 302   BUTTON_15
key 303   BUTTON_16


key 304   BUTTON_A
key 305   BUTTON_B
key 306   BUTTON_C
key 307   BUTTON_X
key 308   BUTTON_Y
key 309   BUTTON_Z
key 310   BUTTON_L1
key 311   BUTTON_R1
key 312   BUTTON_L2
key 313   BUTTON_R2
key 314   BUTTON_SELECT
key 315   BUTTON_START
key 316   BUTTON_MODE
key 317   BUTTON_THUMBL
key 318   BUTTON_THUMBR


# key 352 "KEY_OK"
key 353   DPAD_CENTER
# key 354 "KEY_GOTO"
# key 355 "KEY_CLEAR"
# key 356 "KEY_POWER2"
# key 357 "KEY_OPTION"
# key 358 "KEY_INFO"
# key 359 "KEY_TIME"
# key 360 "KEY_VENDOR"
# key 361 "KEY_ARCHIVE"
key 362   GUIDE
# key 363 "KEY_CHANNEL"
# key 364 "KEY_FAVORITES"
# key 365 "KEY_EPG"
key 366   DVR
# key 367 "KEY_MHP"
# key 368 "KEY_LANGUAGE"
# key 369 "KEY_TITLE"
# key 370 "KEY_SUBTITLE"
# key 371 "KEY_ANGLE"
# key 372 "KEY_ZOOM"
# key 373 "KEY_MODE"
# key 374 "KEY_KEYBOARD"
# key 375 "KEY_SCREEN"
# key 376 "KEY_PC"
key 377   TV
# key 378 "KEY_TV2"
# key 379 "KEY_VCR"
# key 380 "KEY_VCR2"
# key 381 "KEY_SAT"
# key 382 "KEY_SAT2"
# key 383 "KEY_CD"
# key 384 "KEY_TAPE"
# key 385 "KEY_RADIO"
# key 386 "KEY_TUNER"
# key 387 "KEY_PLAYER"
# key 388 "KEY_TEXT"
# key 389 "KEY_DVD"
# key 390 "KEY_AUX"
# key 391 "KEY_MP3"
# key 392 "KEY_AUDIO"
# key 393 "KEY_VIDEO"
# key 394 "KEY_DIRECTORY"
# key 395 "KEY_LIST"
# key 396 "KEY_MEMO"
key 397   CALENDAR
# key 398 "KEY_RED"
# key 399 "KEY_GREEN"
# key 400 "KEY_YELLOW"
# key 401 "KEY_BLUE"
key 402   CHANNEL_UP
key 403   CHANNEL_DOWN
# key 404 "KEY_FIRST"
# key 405 "KEY_LAST"
# key 406 "KEY_AB"
# key 407 "KEY_NEXT"
# key 408 "KEY_RESTART"
# key 409 "KEY_SLOW"
# key 410 "KEY_SHUFFLE"
# key 411 "KEY_BREAK"
# key 412 "KEY_PREVIOUS"
# key 413 "KEY_DIGITS"
# key 414 "KEY_TEEN"
# key 415 "KEY_TWEN"

key 429   CONTACTS

# key 448 "KEY_DEL_EOL"
# key 449 "KEY_DEL_EOS"
# key 450 "KEY_INS_LINE"
# key 451 "KEY_DEL_LINE"


key 464   FUNCTION
key 465   ESCAPE            FUNCTION
key 466   F1                FUNCTION
key 467   F2                FUNCTION
key 468   F3                FUNCTION
key 469   F4                FUNCTION
key 470   F5                FUNCTION
key 471   F6                FUNCTION
key 472   F7                FUNCTION
key 473   F8                FUNCTION
key 474   F9                FUNCTION
key 475   F10               FUNCTION
key 476   F11               FUNCTION
key 477   F12               FUNCTION
key 478   1                 FUNCTION
key 479   2                 FUNCTION
key 480   D                 FUNCTION
key 481   E                 FUNCTION
key 482   F                 FUNCTION
key 483   S                 FUNCTION
key 484   B                 FUNCTION


# key 497 KEY_BRL_DOT1
# key 498 KEY_BRL_DOT2
# key 499 KEY_BRL_DOT3
# key 500 KEY_BRL_DOT4
# key 501 KEY_BRL_DOT5
# key 502 KEY_BRL_DOT6
# key 503 KEY_BRL_DOT7
# key 504 KEY_BRL_DOT8


# Joystick and game controller axes.
# Axes that are not mapped will be assigned generic axis numbers by the input subsystem.
axis 0x00 X
axis 0x01 Y
axis 0x02 Z
axis 0x03 RX
axis 0x04 RY
axis 0x05 RZ
axis 0x06 THROTTLE
axis 0x07 RUDDER
axis 0x08 WHEEL
axis 0x09 GAS
axis 0x0a BRAKE
axis 0x10 HAT_X
axis 0x11 HAT_Y

 key  158   BACK WAKE_DROPPED

类型  CODE  NAME

有些没有用到的用'#'注释

 

kernel/include/linux/input.h

#ifndef _INPUT_H
#define _INPUT_H

/*
 * Copyright (c) 1999-2002 Vojtech Pavlik
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */

#ifdef __KERNEL__
#include 
#include 
#else
#include 
#include 
#include 
#include 
#endif

/*
 * The event structure itself
 */

struct input_event {
	struct timeval time;
	__u16 type;
	__u16 code;
	__s32 value;
};

/*
 * Protocol version.
 */

#define EV_VERSION		0x010001

/*
 * IOCTLs (0x00 - 0x7f)
 */

struct input_id {
	__u16 bustype;
	__u16 vendor;
	__u16 product;
	__u16 version;
};

/**
 * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
 * @value: latest reported value for the axis.
 * @minimum: specifies minimum value for the axis.
 * @maximum: specifies maximum value for the axis.
 * @fuzz: specifies fuzz value that is used to filter noise from
 *	the event stream.
 * @flat: values that are within this value will be discarded by
 *	joydev interface and reported as 0 instead.
 * @resolution: specifies resolution for the values reported for
 *	the axis.
 *
 * Note that input core does not clamp reported values to the
 * [minimum, maximum] limits, such task is left to userspace.
 *
 * Resolution for main axes (ABS_X, ABS_Y, ABS_Z) is reported in
 * units per millimeter (units/mm), resolution for rotational axes
 * (ABS_RX, ABS_RY, ABS_RZ) is reported in units per radian.
 */
struct input_absinfo {
	__s32 value;
	__s32 minimum;
	__s32 maximum;
	__s32 fuzz;
	__s32 flat;
	__s32 resolution;
};

/**
 * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
 * @scancode: scancode represented in machine-endian form.
 * @len: length of the scancode that resides in @scancode buffer.
 * @index: index in the keymap, may be used instead of scancode
 * @flags: allows to specify how kernel should handle the request. For
 *	example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
 *	should perform lookup in keymap by @index instead of @scancode
 * @keycode: key code assigned to this scancode
 *
 * The structure is used to retrieve and modify keymap data. Users have
 * option of performing lookup either by @scancode itself or by @index
 * in keymap entry. EVIOCGKEYCODE will also return scancode or index
 * (depending on which element was used to perform lookup).
 */
struct input_keymap_entry {
#define INPUT_KEYMAP_BY_INDEX	(1 << 0)
	__u8  flags;
	__u8  len;
	__u16 index;
	__u32 keycode;
	__u8  scancode[32];
};

#define EVIOCGVERSION		_IOR('E', 0x01, int)			/* get driver version */
#define EVIOCGID		_IOR('E', 0x02, struct input_id)	/* get device ID */
#define EVIOCGREP		_IOR('E', 0x03, unsigned int[2])	/* get repeat settings */
#define EVIOCSREP		_IOW('E', 0x03, unsigned int[2])	/* set repeat settings */

#define EVIOCGKEYCODE		_IOR('E', 0x04, unsigned int[2])        /* get keycode */
#define EVIOCGKEYCODE_V2	_IOR('E', 0x04, struct input_keymap_entry)
#define EVIOCSKEYCODE		_IOW('E', 0x04, unsigned int[2])        /* set keycode */
#define EVIOCSKEYCODE_V2	_IOW('E', 0x04, struct input_keymap_entry)

#define EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, len)		/* get device name */
#define EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, len)		/* get physical location */
#define EVIOCGUNIQ(len)		_IOC(_IOC_READ, 'E', 0x08, len)		/* get unique identifier */
#define EVIOCGPROP(len)		_IOC(_IOC_READ, 'E', 0x09, len)		/* get device properties */

#define EVIOCGKEY(len)		_IOC(_IOC_READ, 'E', 0x18, len)		/* get global key state */
#define EVIOCGLED(len)		_IOC(_IOC_READ, 'E', 0x19, len)		/* get all LEDs */
#define EVIOCGSND(len)		_IOC(_IOC_READ, 'E', 0x1a, len)		/* get all sounds status */
#define EVIOCGSW(len)		_IOC(_IOC_READ, 'E', 0x1b, len)		/* get all switch states */

#define EVIOCGBIT(ev,len)	_IOC(_IOC_READ, 'E', 0x20 + ev, len)	/* get event bits */
#define EVIOCGABS(abs)		_IOR('E', 0x40 + abs, struct input_absinfo)	/* get abs value/limits */
#define EVIOCSABS(abs)		_IOW('E', 0xc0 + abs, struct input_absinfo)	/* set abs value/limits */

#define EVIOCSFF		_IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect))	/* send a force effect to a force feedback device */
#define EVIOCRMFF		_IOW('E', 0x81, int)			/* Erase a force effect */
#define EVIOCGEFFECTS		_IOR('E', 0x84, int)			/* Report number of effects playable at the same time */

#define EVIOCGRAB		_IOW('E', 0x90, int)			/* Grab/Release device */

#define EVIOCGSUSPENDBLOCK	_IOR('E', 0x91, int)			/* get suspend block enable */
#define EVIOCSSUSPENDBLOCK	_IOW('E', 0x91, int)			/* set suspend block enable */

/*
 * Device properties and quirks
 */

#define INPUT_PROP_POINTER		0x00	/* needs a pointer */
#define INPUT_PROP_DIRECT		0x01	/* direct input devices */
#define INPUT_PROP_BUTTONPAD		0x02	/* has button(s) under pad */
#define INPUT_PROP_SEMI_MT		0x03	/* touch rectangle only */

#define INPUT_PROP_MAX			0x1f
#define INPUT_PROP_CNT			(INPUT_PROP_MAX + 1)

/*
 * Event types
 */

#define EV_SYN			0x00
#define EV_KEY			0x01
#define EV_REL			0x02
#define EV_ABS			0x03
#define EV_MSC			0x04
#define EV_SW			0x05
#define EV_LED			0x11
#define EV_SND			0x12
#define EV_REP			0x14
#define EV_FF			0x15
#define EV_PWR			0x16
#define EV_FF_STATUS		0x17
#define EV_MAX			0x1f
#define EV_CNT			(EV_MAX+1)

/*
 * Synchronization events.
 */

#define SYN_REPORT		0
#define SYN_CONFIG		1
#define SYN_MT_REPORT		2
#define SYN_DROPPED		3

/*
 * Keys and buttons
 *
 * Most of the keys/buttons are modeled after USB HUT 1.12
 * (see http://www.usb.org/developers/hidpage).
 * Abbreviations in the comments:
 * AC - Application Control
 * AL - Application Launch Button
 * SC - System Control
 */

#define KEY_RESERVED		0
#define KEY_ESC			1
#define KEY_1			2
#define KEY_2			3
#define KEY_3			4
#define KEY_4			5
#define KEY_5			6
#define KEY_6			7
#define KEY_7			8
#define KEY_8			9
#define KEY_9			10
#define KEY_0			11
#define KEY_MINUS		12
#define KEY_EQUAL		13
#define KEY_BACKSPACE		14
#define KEY_TAB			15
#define KEY_Q			16
#define KEY_W			17
#define KEY_E			18
#define KEY_R			19
#define KEY_T			20
#define KEY_Y			21
#define KEY_U			22
#define KEY_I			23
#define KEY_O			24
#define KEY_P			25
#define KEY_LEFTBRACE		26
#define KEY_RIGHTBRACE		27
#define KEY_ENTER		28
#define KEY_LEFTCTRL		29
#define KEY_A			30
#define KEY_S			31
#define KEY_D			32
#define KEY_F			33
#define KEY_G			34
#define KEY_H			35
#define KEY_J			36
#define KEY_K			37
#define KEY_L			38
#define KEY_SEMICOLON		39
#define KEY_APOSTROPHE		40
#define KEY_GRAVE		41
#define KEY_LEFTSHIFT		42
#define KEY_BACKSLASH		43
#define KEY_Z			44
#define KEY_X			45
#define KEY_C			46
#define KEY_V			47
#define KEY_B			48
#define KEY_N			49
#define KEY_M			50
#define KEY_COMMA		51
#define KEY_DOT			52
#define KEY_SLASH		53
#define KEY_RIGHTSHIFT		54
#define KEY_KPASTERISK		55
#define KEY_LEFTALT		56
#define KEY_SPACE		57
#define KEY_CAPSLOCK		58
#define KEY_F1			59
#define KEY_F2			60
#define KEY_F3			61
#define KEY_F4			62
#define KEY_F5			63
#define KEY_F6			64
#define KEY_F7			65
#define KEY_F8			66
#define KEY_F9			67
#define KEY_F10			68
#define KEY_NUMLOCK		69
#define KEY_SCROLLLOCK		70
#define KEY_KP7			71
#define KEY_KP8			72
#define KEY_KP9			73
#define KEY_KPMINUS		74
#define KEY_KP4			75
#define KEY_KP5			76
#define KEY_KP6			77
#define KEY_KPPLUS		78
#define KEY_KP1			79
#define KEY_KP2			80
#define KEY_KP3			81
#define KEY_KP0			82
#define KEY_KPDOT		83

#define KEY_ZENKAKUHANKAKU	85
#define KEY_102ND		86
#define KEY_F11			87
#define KEY_F12			88
#define KEY_RO			89
#define KEY_KATAKANA		90
#define KEY_HIRAGANA		91
#define KEY_HENKAN		92
#define KEY_KATAKANAHIRAGANA	93
#define KEY_MUHENKAN		94
#define KEY_KPJPCOMMA		95
#define KEY_KPENTER		96
#define KEY_RIGHTCTRL		97
#define KEY_KPSLASH		98
#define KEY_SYSRQ		99
#define KEY_RIGHTALT		100
#define KEY_LINEFEED		101
#define KEY_HOME		102
#define KEY_UP			103
#define KEY_PAGEUP		104
#define KEY_LEFT		105
#define KEY_RIGHT		106
#define KEY_END			107
#define KEY_DOWN		108
#define KEY_PAGEDOWN		109
#define KEY_INSERT		110
#define KEY_DELETE		111
#define KEY_MACRO		112
#define KEY_MUTE		113
#define KEY_VOLUMEDOWN		114
#define KEY_VOLUMEUP		115
#define KEY_POWER		116	/* SC System Power Down */
#define KEY_KPEQUAL		117
#define KEY_KPPLUSMINUS		118
#define KEY_PAUSE		119
#define KEY_SCALE		120	/* AL Compiz Scale (Expose) */

#define KEY_KPCOMMA		121
#define KEY_HANGEUL		122
#define KEY_HANGUEL		KEY_HANGEUL
#define KEY_HANJA		123
#define KEY_YEN			124
#define KEY_LEFTMETA		125
#define KEY_RIGHTMETA		126
#define KEY_COMPOSE		127

#define KEY_STOP		128	/* AC Stop */
#define KEY_AGAIN		129
#define KEY_PROPS		130	/* AC Properties */
#define KEY_UNDO		131	/* AC Undo */
#define KEY_FRONT		132
#define KEY_COPY		133	/* AC Copy */
#define KEY_OPEN		134	/* AC Open */
#define KEY_PASTE		135	/* AC Paste */
#define KEY_FIND		136	/* AC Search */
#define KEY_CUT			137	/* AC Cut */
#define KEY_HELP		138	/* AL Integrated Help Center */
#define KEY_MENU		139	/* Menu (show menu) */
#define KEY_CALC		140	/* AL Calculator */
#define KEY_SETUP		141
#define KEY_SLEEP		142	/* SC System Sleep */
#define KEY_WAKEUP		143	/* System Wake Up */
#define KEY_FILE		144	/* AL Local Machine Browser */
#define KEY_SENDFILE		145
#define KEY_DELETEFILE		146
#define KEY_XFER		147
#define KEY_PROG1		148
#define KEY_PROG2		149
#define KEY_WWW			150	/* AL Internet Browser */
#define KEY_MSDOS		151
#define KEY_COFFEE		152	/* AL Terminal Lock/Screensaver */
#define KEY_SCREENLOCK		KEY_COFFEE
#define KEY_DIRECTION		153
#define KEY_CYCLEWINDOWS	154
#define KEY_MAIL		155
#define KEY_BOOKMARKS		156	/* AC Bookmarks */
#define KEY_COMPUTER		157
#define KEY_BACK		158	/* AC Back */
#define KEY_FORWARD		159	/* AC Forward */
#define KEY_CLOSECD		160
#define KEY_EJECTCD		161
#define KEY_EJECTCLOSECD	162
#define KEY_NEXTSONG		163
#define KEY_PLAYPAUSE		164
#define KEY_PREVIOUSSONG	165
#define KEY_STOPCD		166
#define KEY_RECORD		167
#define KEY_REWIND		168
#define KEY_PHONE		169	/* Media Select Telephone */
#define KEY_ISO			170
#define KEY_CONFIG		171	/* AL Consumer Control Configuration */
#define KEY_HOMEPAGE		172	/* AC Home */
#define KEY_REFRESH		173	/* AC Refresh */
#define KEY_EXIT		174	/* AC Exit */
#define KEY_MOVE		175
#define KEY_EDIT		176
#define KEY_SCROLLUP		177
#define KEY_SCROLLDOWN		178
#define KEY_KPLEFTPAREN		179
#define KEY_KPRIGHTPAREN	180
#define KEY_NEW			181	/* AC New */
#define KEY_REDO		182	/* AC Redo/Repeat */

#define KEY_F13			183
#define KEY_F14			184
#define KEY_F15			185
#define KEY_F16			186
#define KEY_F17			187
#define KEY_F18			188
#define KEY_F19			189
#define KEY_F20			190
#define KEY_F21			191
#define KEY_F22			192
#define KEY_F23			193
#define KEY_F24			194

#define KEY_PLAYCD		200
#define KEY_PAUSECD		201
#define KEY_PROG3		202
#define KEY_PROG4		203
#define KEY_DASHBOARD		204	/* AL Dashboard */
#define KEY_SUSPEND		205
#define KEY_CLOSE		206	/* AC Close */
#define KEY_PLAY		207
#define KEY_FASTFORWARD		208
#define KEY_BASSBOOST		209
#define KEY_PRINT		210	/* AC Print */
#define KEY_HP			211
#define KEY_CAMERA		212
#define KEY_SOUND		213
#define KEY_QUESTION		214
#define KEY_EMAIL		215
#define KEY_CHAT		216
#define KEY_SEARCH		217
#define KEY_CONNECT		218
#define KEY_FINANCE		219	/* AL Checkbook/Finance */
#define KEY_SPORT		220
#define KEY_SHOP		221
#define KEY_ALTERASE		222
#define KEY_CANCEL		223	/* AC Cancel */
#define KEY_BRIGHTNESSDOWN	224
#define KEY_BRIGHTNESSUP	225
#define KEY_MEDIA		226

#define KEY_SWITCHVIDEOMODE	227	/* Cycle between available video
					   outputs (Monitor/LCD/TV-out/etc) */
#define KEY_KBDILLUMTOGGLE	228
#define KEY_KBDILLUMDOWN	229
#define KEY_KBDILLUMUP		230

#define KEY_SEND		231	/* AC Send */
#define KEY_REPLY		232	/* AC Reply */
#define KEY_FORWARDMAIL		233	/* AC Forward Msg */
#define KEY_SAVE		234	/* AC Save */
#define KEY_DOCUMENTS		235

#define KEY_BATTERY		236

#define KEY_BLUETOOTH		237
#define KEY_WLAN		238
#define KEY_UWB			239

#define KEY_UNKNOWN		240

#define KEY_VIDEO_NEXT		241	/* drive next video source */
#define KEY_VIDEO_PREV		242	/* drive previous video source */
#define KEY_BRIGHTNESS_CYCLE	243	/* brightness up, after max is min */
#define KEY_BRIGHTNESS_ZERO	244	/* brightness off, use ambient */
#define KEY_DISPLAY_OFF		245	/* display device to off state */

#define KEY_WIMAX		246
#define KEY_RFKILL		247	/* Key that controls all radios */

/* Code 255 is reserved for special needs of AT keyboard driver */

#define BTN_MISC		0x100
#define BTN_0			0x100
#define BTN_1			0x101
#define BTN_2			0x102
#define BTN_3			0x103
#define BTN_4			0x104
#define BTN_5			0x105
#define BTN_6			0x106
#define BTN_7			0x107
#define BTN_8			0x108
#define BTN_9			0x109

#define BTN_MOUSE		0x110
#define BTN_LEFT		0x110
#define BTN_RIGHT		0x111
#define BTN_MIDDLE		0x112
#define BTN_SIDE		0x113
#define BTN_EXTRA		0x114
#define BTN_FORWARD		0x115
#define BTN_BACK		0x116
#define BTN_TASK		0x117

#define BTN_JOYSTICK		0x120
#define BTN_TRIGGER		0x120
#define BTN_THUMB		0x121
#define BTN_THUMB2		0x122
#define BTN_TOP			0x123
#define BTN_TOP2		0x124
#define BTN_PINKIE		0x125
#define BTN_BASE		0x126
#define BTN_BASE2		0x127
#define BTN_BASE3		0x128
#define BTN_BASE4		0x129
#define BTN_BASE5		0x12a
#define BTN_BASE6		0x12b
#define BTN_DEAD		0x12f

#define BTN_GAMEPAD		0x130
#define BTN_A			0x130
#define BTN_B			0x131
#define BTN_C			0x132
#define BTN_X			0x133
#define BTN_Y			0x134
#define BTN_Z			0x135
#define BTN_TL			0x136
#define BTN_TR			0x137
#define BTN_TL2			0x138
#define BTN_TR2			0x139
#define BTN_SELECT		0x13a
#define BTN_START		0x13b
#define BTN_MODE		0x13c
#define BTN_THUMBL		0x13d
#define BTN_THUMBR		0x13e

#define BTN_DIGI		0x140
#define BTN_TOOL_PEN		0x140
#define BTN_TOOL_RUBBER		0x141
#define BTN_TOOL_BRUSH		0x142
#define BTN_TOOL_PENCIL		0x143
#define BTN_TOOL_AIRBRUSH	0x144
#define BTN_TOOL_FINGER		0x145
#define BTN_TOOL_MOUSE		0x146
#define BTN_TOOL_LENS		0x147
#define BTN_TOUCH		0x14a
#define BTN_STYLUS		0x14b
#define BTN_STYLUS2		0x14c
#define BTN_TOOL_DOUBLETAP	0x14d
#define BTN_TOOL_TRIPLETAP	0x14e
#define BTN_TOOL_QUADTAP	0x14f	/* Four fingers on trackpad */

#define BTN_WHEEL		0x150
#define BTN_GEAR_DOWN		0x150
#define BTN_GEAR_UP		0x151

#define KEY_OK			0x160
#define KEY_SELECT		0x161
#define KEY_GOTO		0x162
#define KEY_CLEAR		0x163
#define KEY_POWER2		0x164
#define KEY_OPTION		0x165
#define KEY_INFO		0x166	/* AL OEM Features/Tips/Tutorial */
#define KEY_TIME		0x167
#define KEY_VENDOR		0x168
#define KEY_ARCHIVE		0x169
#define KEY_PROGRAM		0x16a	/* Media Select Program Guide */
#define KEY_CHANNEL		0x16b
#define KEY_FAVORITES		0x16c
#define KEY_EPG			0x16d
#define KEY_PVR			0x16e	/* Media Select Home */
#define KEY_MHP			0x16f
#define KEY_LANGUAGE		0x170
#define KEY_TITLE		0x171
#define KEY_SUBTITLE		0x172
#define KEY_ANGLE		0x173
#define KEY_ZOOM		0x174
#define KEY_MODE		0x175
#define KEY_KEYBOARD		0x176
#define KEY_SCREEN		0x177
#define KEY_PC			0x178	/* Media Select Computer */
#define KEY_TV			0x179	/* Media Select TV */
#define KEY_TV2			0x17a	/* Media Select Cable */
#define KEY_VCR			0x17b	/* Media Select VCR */
#define KEY_VCR2		0x17c	/* VCR Plus */
#define KEY_SAT			0x17d	/* Media Select Satellite */
#define KEY_SAT2		0x17e
#define KEY_CD			0x17f	/* Media Select CD */
#define KEY_TAPE		0x180	/* Media Select Tape */
#define KEY_RADIO		0x181
#define KEY_TUNER		0x182	/* Media Select Tuner */
#define KEY_PLAYER		0x183
#define KEY_TEXT		0x184
#define KEY_DVD			0x185	/* Media Select DVD */
#define KEY_AUX			0x186
#define KEY_MP3			0x187
#define KEY_AUDIO		0x188	/* AL Audio Browser */
#define KEY_VIDEO		0x189	/* AL Movie Browser */
#define KEY_DIRECTORY		0x18a
#define KEY_LIST		0x18b
#define KEY_MEMO		0x18c	/* Media Select Messages */
#define KEY_CALENDAR		0x18d
#define KEY_RED			0x18e
#define KEY_GREEN		0x18f
#define KEY_YELLOW		0x190
#define KEY_BLUE		0x191
#define KEY_CHANNELUP		0x192	/* Channel Increment */
#define KEY_CHANNELDOWN		0x193	/* Channel Decrement */
#define KEY_FIRST		0x194
#define KEY_LAST		0x195	/* Recall Last */
#define KEY_AB			0x196
#define KEY_NEXT		0x197
#define KEY_RESTART		0x198
#define KEY_SLOW		0x199
#define KEY_SHUFFLE		0x19a
#define KEY_BREAK		0x19b
#define KEY_PREVIOUS		0x19c
#define KEY_DIGITS		0x19d
#define KEY_TEEN		0x19e
#define KEY_TWEN		0x19f
#define KEY_VIDEOPHONE		0x1a0	/* Media Select Video Phone */
#define KEY_GAMES		0x1a1	/* Media Select Games */
#define KEY_ZOOMIN		0x1a2	/* AC Zoom In */
#define KEY_ZOOMOUT		0x1a3	/* AC Zoom Out */
#define KEY_ZOOMRESET		0x1a4	/* AC Zoom */
#define KEY_WORDPROCESSOR	0x1a5	/* AL Word Processor */
#define KEY_EDITOR		0x1a6	/* AL Text Editor */
#define KEY_SPREADSHEET		0x1a7	/* AL Spreadsheet */
#define KEY_GRAPHICSEDITOR	0x1a8	/* AL Graphics Editor */
#define KEY_PRESENTATION	0x1a9	/* AL Presentation App */
#define KEY_DATABASE		0x1aa	/* AL Database App */
#define KEY_NEWS		0x1ab	/* AL Newsreader */
#define KEY_VOICEMAIL		0x1ac	/* AL Voicemail */
#define KEY_ADDRESSBOOK		0x1ad	/* AL Contacts/Address Book */
#define KEY_MESSENGER		0x1ae	/* AL Instant Messaging */
#define KEY_DISPLAYTOGGLE	0x1af	/* Turn display (LCD) on and off */
#define KEY_SPELLCHECK		0x1b0   /* AL Spell Check */
#define KEY_LOGOFF		0x1b1   /* AL Logoff */

#define KEY_DOLLAR		0x1b2
#define KEY_EURO		0x1b3

#define KEY_FRAMEBACK		0x1b4	/* Consumer - transport controls */
#define KEY_FRAMEFORWARD	0x1b5
#define KEY_CONTEXT_MENU	0x1b6	/* GenDesc - system context menu */
#define KEY_MEDIA_REPEAT	0x1b7	/* Consumer - transport control */
#define KEY_10CHANNELSUP	0x1b8	/* 10 channels up (10+) */
#define KEY_10CHANNELSDOWN	0x1b9	/* 10 channels down (10-) */
#define KEY_IMAGES		0x1ba	/* AL Image Browser */

#define KEY_DEL_EOL		0x1c0
#define KEY_DEL_EOS		0x1c1
#define KEY_INS_LINE		0x1c2
#define KEY_DEL_LINE		0x1c3

#define KEY_FN			0x1d0
#define KEY_FN_ESC		0x1d1
#define KEY_FN_F1		0x1d2
#define KEY_FN_F2		0x1d3
#define KEY_FN_F3		0x1d4
#define KEY_FN_F4		0x1d5
#define KEY_FN_F5		0x1d6
#define KEY_FN_F6		0x1d7
#define KEY_FN_F7		0x1d8
#define KEY_FN_F8		0x1d9
#define KEY_FN_F9		0x1da
#define KEY_FN_F10		0x1db
#define KEY_FN_F11		0x1dc
#define KEY_FN_F12		0x1dd
#define KEY_FN_1		0x1de
#define KEY_FN_2		0x1df
#define KEY_FN_D		0x1e0
#define KEY_FN_E		0x1e1
#define KEY_FN_F		0x1e2
#define KEY_FN_S		0x1e3
#define KEY_FN_B		0x1e4

#define KEY_BRL_DOT1		0x1f1
#define KEY_BRL_DOT2		0x1f2
#define KEY_BRL_DOT3		0x1f3
#define KEY_BRL_DOT4		0x1f4
#define KEY_BRL_DOT5		0x1f5
#define KEY_BRL_DOT6		0x1f6
#define KEY_BRL_DOT7		0x1f7
#define KEY_BRL_DOT8		0x1f8
#define KEY_BRL_DOT9		0x1f9
#define KEY_BRL_DOT10		0x1fa

#define KEY_NUMERIC_0		0x200	/* used by phones, remote controls, */
#define KEY_NUMERIC_1		0x201	/* and other keypads */
#define KEY_NUMERIC_2		0x202
#define KEY_NUMERIC_3		0x203
#define KEY_NUMERIC_4		0x204
#define KEY_NUMERIC_5		0x205
#define KEY_NUMERIC_6		0x206
#define KEY_NUMERIC_7		0x207
#define KEY_NUMERIC_8		0x208
#define KEY_NUMERIC_9		0x209
#define KEY_NUMERIC_STAR	0x20a
#define KEY_NUMERIC_POUND	0x20b

#define KEY_CAMERA_FOCUS	0x210
#define KEY_WPS_BUTTON		0x211	/* WiFi Protected Setup key */

#define KEY_TOUCHPAD_TOGGLE	0x212	/* Request switch touchpad on or off */
#define KEY_TOUCHPAD_ON		0x213
#define KEY_TOUCHPAD_OFF	0x214

#define KEY_CAMERA_ZOOMIN	0x215
#define KEY_CAMERA_ZOOMOUT	0x216
#define KEY_CAMERA_UP		0x217
#define KEY_CAMERA_DOWN		0x218
#define KEY_CAMERA_LEFT		0x219
#define KEY_CAMERA_RIGHT	0x21a

#define BTN_TRIGGER_HAPPY		0x2c0
#define BTN_TRIGGER_HAPPY1		0x2c0
#define BTN_TRIGGER_HAPPY2		0x2c1
#define BTN_TRIGGER_HAPPY3		0x2c2
#define BTN_TRIGGER_HAPPY4		0x2c3
#define BTN_TRIGGER_HAPPY5		0x2c4
#define BTN_TRIGGER_HAPPY6		0x2c5
#define BTN_TRIGGER_HAPPY7		0x2c6
#define BTN_TRIGGER_HAPPY8		0x2c7
#define BTN_TRIGGER_HAPPY9		0x2c8
#define BTN_TRIGGER_HAPPY10		0x2c9
#define BTN_TRIGGER_HAPPY11		0x2ca
#define BTN_TRIGGER_HAPPY12		0x2cb
#define BTN_TRIGGER_HAPPY13		0x2cc
#define BTN_TRIGGER_HAPPY14		0x2cd
#define BTN_TRIGGER_HAPPY15		0x2ce
#define BTN_TRIGGER_HAPPY16		0x2cf
#define BTN_TRIGGER_HAPPY17		0x2d0
#define BTN_TRIGGER_HAPPY18		0x2d1
#define BTN_TRIGGER_HAPPY19		0x2d2
#define BTN_TRIGGER_HAPPY20		0x2d3
#define BTN_TRIGGER_HAPPY21		0x2d4
#define BTN_TRIGGER_HAPPY22		0x2d5
#define BTN_TRIGGER_HAPPY23		0x2d6
#define BTN_TRIGGER_HAPPY24		0x2d7
#define BTN_TRIGGER_HAPPY25		0x2d8
#define BTN_TRIGGER_HAPPY26		0x2d9
#define BTN_TRIGGER_HAPPY27		0x2da
#define BTN_TRIGGER_HAPPY28		0x2db
#define BTN_TRIGGER_HAPPY29		0x2dc
#define BTN_TRIGGER_HAPPY30		0x2dd
#define BTN_TRIGGER_HAPPY31		0x2de
#define BTN_TRIGGER_HAPPY32		0x2df
#define BTN_TRIGGER_HAPPY33		0x2e0
#define BTN_TRIGGER_HAPPY34		0x2e1
#define BTN_TRIGGER_HAPPY35		0x2e2
#define BTN_TRIGGER_HAPPY36		0x2e3
#define BTN_TRIGGER_HAPPY37		0x2e4
#define BTN_TRIGGER_HAPPY38		0x2e5
#define BTN_TRIGGER_HAPPY39		0x2e6
#define BTN_TRIGGER_HAPPY40		0x2e7

/* We avoid low common keys in module aliases so they don't get huge. */
#define KEY_MIN_INTERESTING	KEY_MUTE
#define KEY_MAX			0x2ff
#define KEY_CNT			(KEY_MAX+1)

/*
 * Relative axes
 */

#define REL_X			0x00
#define REL_Y			0x01
#define REL_Z			0x02
#define REL_RX			0x03
#define REL_RY			0x04
#define REL_RZ			0x05
#define REL_HWHEEL		0x06
#define REL_DIAL		0x07
#define REL_WHEEL		0x08
#define REL_MISC		0x09
#define REL_MAX			0x0f
#define REL_CNT			(REL_MAX+1)

/*
 * Absolute axes
 */

#define ABS_X			0x00
#define ABS_Y			0x01
#define ABS_Z			0x02
#define ABS_RX			0x03
#define ABS_RY			0x04
#define ABS_RZ			0x05
#define ABS_THROTTLE		0x06
#define ABS_RUDDER		0x07
#define ABS_WHEEL		0x08
#define ABS_GAS			0x09
#define ABS_BRAKE		0x0a
#define ABS_HAT0X		0x10
#define ABS_HAT0Y		0x11
#define ABS_HAT1X		0x12
#define ABS_HAT1Y		0x13
#define ABS_HAT2X		0x14
#define ABS_HAT2Y		0x15
#define ABS_HAT3X		0x16
#define ABS_HAT3Y		0x17
#define ABS_PRESSURE		0x18
#define ABS_DISTANCE		0x19
#define ABS_TILT_X		0x1a
#define ABS_TILT_Y		0x1b
#define ABS_TOOL_WIDTH		0x1c

#define ABS_VOLUME		0x20

#define ABS_MISC		0x28

#define ABS_MT_SLOT		0x2f	/* MT slot being modified */
#define ABS_MT_TOUCH_MAJOR	0x30	/* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR	0x31	/* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR	0x32	/* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR	0x33	/* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION	0x34	/* Ellipse orientation */
#define ABS_MT_POSITION_X	0x35	/* Center X ellipse position */
#define ABS_MT_POSITION_Y	0x36	/* Center Y ellipse position */
#define ABS_MT_TOOL_TYPE	0x37	/* Type of touching device */
#define ABS_MT_BLOB_ID		0x38	/* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID	0x39	/* Unique ID of initiated contact */
#define ABS_MT_PRESSURE		0x3a	/* Pressure on contact area */
#define ABS_MT_DISTANCE		0x3b	/* Contact hover distance */

#ifdef __KERNEL__
/* Implementation details, userspace should not care about these */
#define ABS_MT_FIRST		ABS_MT_TOUCH_MAJOR
#define ABS_MT_LAST		ABS_MT_DISTANCE
#endif

#define ABS_MAX			0x3f
#define ABS_CNT			(ABS_MAX+1)

/*
 * Switch events
 */

#define SW_LID			0x00  /* set = lid shut */
#define SW_TABLET_MODE		0x01  /* set = tablet mode */
#define SW_HEADPHONE_INSERT	0x02  /* set = inserted */
#define SW_RFKILL_ALL		0x03  /* rfkill master switch, type "any"
					 set = radio enabled */
#define SW_RADIO		SW_RFKILL_ALL	/* deprecated */
#define SW_MICROPHONE_INSERT	0x04  /* set = inserted */
#define SW_DOCK			0x05  /* set = plugged into dock */
#define SW_LINEOUT_INSERT	0x06  /* set = inserted */
#define SW_JACK_PHYSICAL_INSERT 0x07  /* set = mechanical switch set */
#define SW_VIDEOOUT_INSERT	0x08  /* set = inserted */
#define SW_CAMERA_LENS_COVER	0x09  /* set = lens covered */
#define SW_KEYPAD_SLIDE		0x0a  /* set = keypad slide out */
#define SW_FRONT_PROXIMITY	0x0b  /* set = front proximity sensor active */
#define SW_ROTATE_LOCK		0x0c  /* set = rotate locked/disabled */
#define SW_MAX			0x0f
#define SW_CNT			(SW_MAX+1)

/*
 * Misc events
 */

#define MSC_SERIAL		0x00
#define MSC_PULSELED		0x01
#define MSC_GESTURE		0x02
#define MSC_RAW			0x03
#define MSC_SCAN		0x04
#define MSC_MAX			0x07
#define MSC_CNT			(MSC_MAX+1)

/*
 * LEDs
 */

#define LED_NUML		0x00
#define LED_CAPSL		0x01
#define LED_SCROLLL		0x02
#define LED_COMPOSE		0x03
#define LED_KANA		0x04
#define LED_SLEEP		0x05
#define LED_SUSPEND		0x06
#define LED_MUTE		0x07
#define LED_MISC		0x08
#define LED_MAIL		0x09
#define LED_CHARGING		0x0a
#define LED_MAX			0x0f
#define LED_CNT			(LED_MAX+1)

/*
 * Autorepeat values
 */

#define REP_DELAY		0x00
#define REP_PERIOD		0x01
#define REP_MAX			0x01
#define REP_CNT			(REP_MAX+1)

/*
 * Sounds
 */

#define SND_CLICK		0x00
#define SND_BELL		0x01
#define SND_TONE		0x02
#define SND_MAX			0x07
#define SND_CNT			(SND_MAX+1)

/*
 * IDs.
 */

#define ID_BUS			0
#define ID_VENDOR		1
#define ID_PRODUCT		2
#define ID_VERSION		3

#define BUS_PCI			0x01
#define BUS_ISAPNP		0x02
#define BUS_USB			0x03
#define BUS_HIL			0x04
#define BUS_BLUETOOTH		0x05
#define BUS_VIRTUAL		0x06

#define BUS_ISA			0x10
#define BUS_I8042		0x11
#define BUS_XTKBD		0x12
#define BUS_RS232		0x13
#define BUS_GAMEPORT		0x14
#define BUS_PARPORT		0x15
#define BUS_AMIGA		0x16
#define BUS_ADB			0x17
#define BUS_I2C			0x18
#define BUS_HOST		0x19
#define BUS_GSC			0x1A
#define BUS_ATARI		0x1B
#define BUS_SPI			0x1C

/*
 * MT_TOOL types
 */
#define MT_TOOL_FINGER		0
#define MT_TOOL_PEN		1
#define MT_TOOL_MAX		1

/*
 * Values describing the status of a force-feedback effect
 */
#define FF_STATUS_STOPPED	0x00
#define FF_STATUS_PLAYING	0x01
#define FF_STATUS_MAX		0x01

/*
 * Structures used in ioctls to upload effects to a device
 * They are pieces of a bigger structure (called ff_effect)
 */

/*
 * All duration values are expressed in ms. Values above 32767 ms (0x7fff)
 * should not be used and have unspecified results.
 */

/**
 * struct ff_replay - defines scheduling of the force-feedback effect
 * @length: duration of the effect
 * @delay: delay before effect should start playing
 */
struct ff_replay {
	__u16 length;
	__u16 delay;
};

/**
 * struct ff_trigger - defines what triggers the force-feedback effect
 * @button: number of the button triggering the effect
 * @interval: controls how soon the effect can be re-triggered
 */
struct ff_trigger {
	__u16 button;
	__u16 interval;
};

/**
 * struct ff_envelope - generic force-feedback effect envelope
 * @attack_length: duration of the attack (ms)
 * @attack_level: level at the beginning of the attack
 * @fade_length: duration of fade (ms)
 * @fade_level: level at the end of fade
 *
 * The @attack_level and @fade_level are absolute values; when applying
 * envelope force-feedback core will convert to positive/negative
 * value based on polarity of the default level of the effect.
 * Valid range for the attack and fade levels is 0x0000 - 0x7fff
 */
struct ff_envelope {
	__u16 attack_length;
	__u16 attack_level;
	__u16 fade_length;
	__u16 fade_level;
};

/**
 * struct ff_constant_effect - defines parameters of a constant force-feedback effect
 * @level: strength of the effect; may be negative
 * @envelope: envelope data
 */
struct ff_constant_effect {
	__s16 level;
	struct ff_envelope envelope;
};

/**
 * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
 * @start_level: beginning strength of the effect; may be negative
 * @end_level: final strength of the effect; may be negative
 * @envelope: envelope data
 */
struct ff_ramp_effect {
	__s16 start_level;
	__s16 end_level;
	struct ff_envelope envelope;
};

/**
 * struct ff_condition_effect - defines a spring or friction force-feedback effect
 * @right_saturation: maximum level when joystick moved all way to the right
 * @left_saturation: same for the left side
 * @right_coeff: controls how fast the force grows when the joystick moves
 *	to the right
 * @left_coeff: same for the left side
 * @deadband: size of the dead zone, where no force is produced
 * @center: position of the dead zone
 */
struct ff_condition_effect {
	__u16 right_saturation;
	__u16 left_saturation;

	__s16 right_coeff;
	__s16 left_coeff;

	__u16 deadband;
	__s16 center;
};

/**
 * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
 * @waveform: kind of the effect (wave)
 * @period: period of the wave (ms)
 * @magnitude: peak value
 * @offset: mean value of the wave (roughly)
 * @phase: 'horizontal' shift
 * @envelope: envelope data
 * @custom_len: number of samples (FF_CUSTOM only)
 * @custom_data: buffer of samples (FF_CUSTOM only)
 *
 * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
 * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
 * for the time being as no driver supports it yet.
 *
 * Note: the data pointed by custom_data is copied by the driver.
 * You can therefore dispose of the memory after the upload/update.
 */
struct ff_periodic_effect {
	__u16 waveform;
	__u16 period;
	__s16 magnitude;
	__s16 offset;
	__u16 phase;

	struct ff_envelope envelope;

	__u32 custom_len;
	__s16 __user *custom_data;
};

/**
 * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
 * @strong_magnitude: magnitude of the heavy motor
 * @weak_magnitude: magnitude of the light one
 *
 * Some rumble pads have two motors of different weight. Strong_magnitude
 * represents the magnitude of the vibration generated by the heavy one.
 */
struct ff_rumble_effect {
	__u16 strong_magnitude;
	__u16 weak_magnitude;
};

/**
 * struct ff_effect - defines force feedback effect
 * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
 *	FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
 * @id: an unique id assigned to an effect
 * @direction: direction of the effect
 * @trigger: trigger conditions (struct ff_trigger)
 * @replay: scheduling of the effect (struct ff_replay)
 * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
 *	ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
 *	defining effect parameters
 *
 * This structure is sent through ioctl from the application to the driver.
 * To create a new effect application should set its @id to -1; the kernel
 * will return assigned @id which can later be used to update or delete
 * this effect.
 *
 * Direction of the effect is encoded as follows:
 *	0 deg -> 0x0000 (down)
 *	90 deg -> 0x4000 (left)
 *	180 deg -> 0x8000 (up)
 *	270 deg -> 0xC000 (right)
 */
struct ff_effect {
	__u16 type;
	__s16 id;
	__u16 direction;
	struct ff_trigger trigger;
	struct ff_replay replay;

	union {
		struct ff_constant_effect constant;
		struct ff_ramp_effect ramp;
		struct ff_periodic_effect periodic;
		struct ff_condition_effect condition[2]; /* One for each axis */
		struct ff_rumble_effect rumble;
	} u;
};

/*
 * Force feedback effect types
 */

#define FF_RUMBLE	0x50
#define FF_PERIODIC	0x51
#define FF_CONSTANT	0x52
#define FF_SPRING	0x53
#define FF_FRICTION	0x54
#define FF_DAMPER	0x55
#define FF_INERTIA	0x56
#define FF_RAMP		0x57

#define FF_EFFECT_MIN	FF_RUMBLE
#define FF_EFFECT_MAX	FF_RAMP

/*
 * Force feedback periodic effect types
 */

#define FF_SQUARE	0x58
#define FF_TRIANGLE	0x59
#define FF_SINE		0x5a
#define FF_SAW_UP	0x5b
#define FF_SAW_DOWN	0x5c
#define FF_CUSTOM	0x5d

#define FF_WAVEFORM_MIN	FF_SQUARE
#define FF_WAVEFORM_MAX	FF_CUSTOM

/*
 * Set ff device properties
 */

#define FF_GAIN		0x60
#define FF_AUTOCENTER	0x61

#define FF_MAX		0x7f
#define FF_CNT		(FF_MAX+1)

#ifdef __KERNEL__

/*
 * In-kernel definitions.
 */

#include 
#include 
#include 
#include 

/**
 * struct input_dev - represents an input device
 * @name: name of the device
 * @phys: physical path to the device in the system hierarchy
 * @uniq: unique identification code for the device (if device has it)
 * @id: id of the device (struct input_id)
 * @propbit: bitmap of device properties and quirks
 * @evbit: bitmap of types of events supported by the device (EV_KEY,
 *	EV_REL, etc.)
 * @keybit: bitmap of keys/buttons this device has
 * @relbit: bitmap of relative axes for the device
 * @absbit: bitmap of absolute axes for the device
 * @mscbit: bitmap of miscellaneous events supported by the device
 * @ledbit: bitmap of leds present on the device
 * @sndbit: bitmap of sound effects supported by the device
 * @ffbit: bitmap of force feedback effects supported by the device
 * @swbit: bitmap of switches present on the device
 * @hint_events_per_packet: average number of events generated by the
 *	device in a packet (between EV_SYN/SYN_REPORT events). Used by
 *	event handlers to estimate size of the buffer needed to hold
 *	events.
 * @keycodemax: size of keycode table
 * @keycodesize: size of elements in keycode table
 * @keycode: map of scancodes to keycodes for this device
 * @getkeycode: optional legacy method to retrieve current keymap.
 * @setkeycode: optional method to alter current keymap, used to implement
 *	sparse keymaps. If not supplied default mechanism will be used.
 *	The method is being called while holding event_lock and thus must
 *	not sleep
 * @ff: force feedback structure associated with the device if device
 *	supports force feedback effects
 * @repeat_key: stores key code of the last key pressed; used to implement
 *	software autorepeat
 * @timer: timer for software autorepeat
 * @rep: current values for autorepeat parameters (delay, rate)
 * @mt: pointer to array of struct input_mt_slot holding current values
 *	of tracked contacts
 * @mtsize: number of MT slots the device uses
 * @slot: MT slot currently being transmitted
 * @trkid: stores MT tracking ID for the current contact
 * @absinfo: array of &struct input_absinfo elements holding information
 *	about absolute axes (current value, min, max, flat, fuzz,
 *	resolution)
 * @key: reflects current state of device's keys/buttons
 * @led: reflects current state of device's LEDs
 * @snd: reflects current state of sound effects
 * @sw: reflects current state of device's switches
 * @open: this method is called when the very first user calls
 *	input_open_device(). The driver must prepare the device
 *	to start generating events (start polling thread,
 *	request an IRQ, submit URB, etc.)
 * @close: this method is called when the very last user calls
 *	input_close_device().
 * @flush: purges the device. Most commonly used to get rid of force
 *	feedback effects loaded into the device when disconnecting
 *	from it
 * @event: event handler for events sent _to_ the device, like EV_LED
 *	or EV_SND. The device is expected to carry out the requested
 *	action (turn on a LED, play sound, etc.) The call is protected
 *	by @event_lock and must not sleep
 * @grab: input handle that currently has the device grabbed (via
 *	EVIOCGRAB ioctl). When a handle grabs a device it becomes sole
 *	recipient for all input events coming from the device
 * @event_lock: this spinlock is is taken when input core receives
 *	and processes a new event for the device (in input_event()).
 *	Code that accesses and/or modifies parameters of a device
 *	(such as keymap or absmin, absmax, absfuzz, etc.) after device
 *	has been registered with input core must take this lock.
 * @mutex: serializes calls to open(), close() and flush() methods
 * @users: stores number of users (input handlers) that opened this
 *	device. It is used by input_open_device() and input_close_device()
 *	to make sure that dev->open() is only called when the first
 *	user opens device and dev->close() is called when the very
 *	last user closes the device
 * @going_away: marks devices that are in a middle of unregistering and
 *	causes input_open_device*() fail with -ENODEV.
 * @sync: set to %true when there were no new events since last EV_SYN
 * @dev: driver model's view of this device
 * @h_list: list of input handles associated with the device. When
 *	accessing the list dev->mutex must be held
 * @node: used to place the device onto input_dev_list
 */
struct input_dev {
	const char *name;
	const char *phys;
	const char *uniq;
	struct input_id id;

	unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];

	unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
	unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
	unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
	unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
	unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
	unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
	unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
	unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
	unsigned long swbit[BITS_TO_LONGS(SW_CNT)];

	unsigned int hint_events_per_packet;

	unsigned int keycodemax;
	unsigned int keycodesize;
	void *keycode;

	int (*setkeycode)(struct input_dev *dev,
			  const struct input_keymap_entry *ke,
			  unsigned int *old_keycode);
	int (*getkeycode)(struct input_dev *dev,
			  struct input_keymap_entry *ke);

	struct ff_device *ff;

	unsigned int repeat_key;
	struct timer_list timer;

	int rep[REP_CNT];

	struct input_mt_slot *mt;
	int mtsize;
	int slot;
	int trkid;

	struct input_absinfo *absinfo;

	unsigned long key[BITS_TO_LONGS(KEY_CNT)];
	unsigned long led[BITS_TO_LONGS(LED_CNT)];
	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
	unsigned long sw[BITS_TO_LONGS(SW_CNT)];

	int (*open)(struct input_dev *dev);
	void (*close)(struct input_dev *dev);
	int (*flush)(struct input_dev *dev, struct file *file);
	int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);

	struct input_handle __rcu *grab;

	spinlock_t event_lock;
	struct mutex mutex;

	unsigned int users;
	bool going_away;

	bool sync;

	struct device dev;

	struct list_head	h_list;
	struct list_head	node;
};
#define to_input_dev(d) container_of(d, struct input_dev, dev)

/*
 * Verify that we are in sync with input_device_id mod_devicetable.h #defines
 */

#if EV_MAX != INPUT_DEVICE_ID_EV_MAX
#error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
#endif

#if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
#error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
#endif

#if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
#error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
#endif

#if REL_MAX != INPUT_DEVICE_ID_REL_MAX
#error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
#endif

#if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
#error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
#endif

#if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
#error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
#endif

#if LED_MAX != INPUT_DEVICE_ID_LED_MAX
#error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
#endif

#if SND_MAX != INPUT_DEVICE_ID_SND_MAX
#error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
#endif

#if FF_MAX != INPUT_DEVICE_ID_FF_MAX
#error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
#endif

#if SW_MAX != INPUT_DEVICE_ID_SW_MAX
#error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
#endif

#define INPUT_DEVICE_ID_MATCH_DEVICE \
	(INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
#define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
	(INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)

struct input_handle;

/**
 * struct input_handler - implements one of interfaces for input devices
 * @private: driver-specific data
 * @event: event handler. This method is being called by input core with
 *	interrupts disabled and dev->event_lock spinlock held and so
 *	it may not sleep
 * @filter: similar to @event; separates normal event handlers from
 *	"filters".
 * @match: called after comparing device's id with handler's id_table
 *	to perform fine-grained matching between device and handler
 * @connect: called when attaching a handler to an input device
 * @disconnect: disconnects a handler from input device
 * @start: starts handler for given handle. This function is called by
 *	input core right after connect() method and also when a process
 *	that "grabbed" a device releases it
 * @fops: file operations this driver implements
 * @minor: beginning of range of 32 minors for devices this driver
 *	can provide
 * @name: name of the handler, to be shown in /proc/bus/input/handlers
 * @id_table: pointer to a table of input_device_ids this driver can
 *	handle
 * @h_list: list of input handles associated with the handler
 * @node: for placing the driver onto input_handler_list
 *
 * Input handlers attach to input devices and create input handles. There
 * are likely several handlers attached to any given input device at the
 * same time. All of them will get their copy of input event generated by
 * the device.
 *
 * The very same structure is used to implement input filters. Input core
 * allows filters to run first and will not pass event to regular handlers
 * if any of the filters indicate that the event should be filtered (by
 * returning %true from their filter() method).
 *
 * Note that input core serializes calls to connect() and disconnect()
 * methods.
 */
struct input_handler {

	void *private;

	void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
	bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
	bool (*match)(struct input_handler *handler, struct input_dev *dev);
	int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
	void (*disconnect)(struct input_handle *handle);
	void (*start)(struct input_handle *handle);

	const struct file_operations *fops;
	int minor;
	const char *name;

	const struct input_device_id *id_table;

	struct list_head	h_list;
	struct list_head	node;
};

/**
 * struct input_handle - links input device with an input handler
 * @private: handler-specific data
 * @open: counter showing whether the handle is 'open', i.e. should deliver
 *	events from its device
 * @name: name given to the handle by handler that created it
 * @dev: input device the handle is attached to
 * @handler: handler that works with the device through this handle
 * @d_node: used to put the handle on device's list of attached handles
 * @h_node: used to put the handle on handler's list of handles from which
 *	it gets events
 */
struct input_handle {

	void *private;

	int open;
	const char *name;

	struct input_dev *dev;
	struct input_handler *handler;

	struct list_head	d_node;
	struct list_head	h_node;
};

struct input_dev *input_allocate_device(void);
void input_free_device(struct input_dev *dev);

static inline struct input_dev *input_get_device(struct input_dev *dev)
{
	return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
}

static inline void input_put_device(struct input_dev *dev)
{
	if (dev)
		put_device(&dev->dev);
}

static inline void *input_get_drvdata(struct input_dev *dev)
{
	return dev_get_drvdata(&dev->dev);
}

static inline void input_set_drvdata(struct input_dev *dev, void *data)
{
	dev_set_drvdata(&dev->dev, data);
}

int __must_check input_register_device(struct input_dev *);
void input_unregister_device(struct input_dev *);

void input_reset_device(struct input_dev *);

int __must_check input_register_handler(struct input_handler *);
void input_unregister_handler(struct input_handler *);

int input_handler_for_each_handle(struct input_handler *, void *data,
				  int (*fn)(struct input_handle *, void *));

int input_register_handle(struct input_handle *);
void input_unregister_handle(struct input_handle *);

int input_grab_device(struct input_handle *);
void input_release_device(struct input_handle *);

int input_open_device(struct input_handle *);
void input_close_device(struct input_handle *);

int input_flush_device(struct input_handle *handle, struct file *file);

void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);

static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
{
	input_event(dev, EV_KEY, code, !!value);
}

static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
{
	input_event(dev, EV_REL, code, value);
}

static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
{
	input_event(dev, EV_ABS, code, value);
}

static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
{
	input_event(dev, EV_FF_STATUS, code, value);
}

static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
{
	input_event(dev, EV_SW, code, !!value);
}

static inline void input_sync(struct input_dev *dev)
{
	input_event(dev, EV_SYN, SYN_REPORT, 0);
}

static inline void input_mt_sync(struct input_dev *dev)
{
	input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
}

void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);

/**
 * input_set_events_per_packet - tell handlers about the driver event rate
 * @dev: the input device used by the driver
 * @n_events: the average number of events between calls to input_sync()
 *
 * If the event rate sent from a device is unusually large, use this
 * function to set the expected event rate. This will allow handlers
 * to set up an appropriate buffer size for the event stream, in order
 * to minimize information loss.
 */
static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
{
	dev->hint_events_per_packet = n_events;
}

void input_alloc_absinfo(struct input_dev *dev);
void input_set_abs_params(struct input_dev *dev, unsigned int axis,
			  int min, int max, int fuzz, int flat);

#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)			\
static inline int input_abs_get_##_suffix(struct input_dev *dev,	\
					  unsigned int axis)		\
{									\
	return dev->absinfo ? dev->absinfo[axis]._item : 0;		\
}									\
									\
static inline void input_abs_set_##_suffix(struct input_dev *dev,	\
					   unsigned int axis, int val)	\
{									\
	input_alloc_absinfo(dev);					\
	if (dev->absinfo)						\
		dev->absinfo[axis]._item = val;				\
}

INPUT_GENERATE_ABS_ACCESSORS(val, value)
INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
INPUT_GENERATE_ABS_ACCESSORS(res, resolution)

int input_scancode_to_scalar(const struct input_keymap_entry *ke,
			     unsigned int *scancode);

int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
int input_set_keycode(struct input_dev *dev,
		      const struct input_keymap_entry *ke);

extern struct class input_class;

/**
 * struct ff_device - force-feedback part of an input device
 * @upload: Called to upload an new effect into device
 * @erase: Called to erase an effect from device
 * @playback: Called to request device to start playing specified effect
 * @set_gain: Called to set specified gain
 * @set_autocenter: Called to auto-center device
 * @destroy: called by input core when parent input device is being
 *	destroyed
 * @private: driver-specific data, will be freed automatically
 * @ffbit: bitmap of force feedback capabilities truly supported by
 *	device (not emulated like ones in input_dev->ffbit)
 * @mutex: mutex for serializing access to the device
 * @max_effects: maximum number of effects supported by device
 * @effects: pointer to an array of effects currently loaded into device
 * @effect_owners: array of effect owners; when file handle owning
 *	an effect gets closed the effect is automatically erased
 *
 * Every force-feedback device must implement upload() and playback()
 * methods; erase() is optional. set_gain() and set_autocenter() need
 * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER
 * bits.
 *
 * Note that playback(), set_gain() and set_autocenter() are called with
 * dev->event_lock spinlock held and interrupts off and thus may not
 * sleep.
 */
struct ff_device {
	int (*upload)(struct input_dev *dev, struct ff_effect *effect,
		      struct ff_effect *old);
	int (*erase)(struct input_dev *dev, int effect_id);

	int (*playback)(struct input_dev *dev, int effect_id, int value);
	void (*set_gain)(struct input_dev *dev, u16 gain);
	void (*set_autocenter)(struct input_dev *dev, u16 magnitude);

	void (*destroy)(struct ff_device *);

	void *private;

	unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];

	struct mutex mutex;

	int max_effects;
	struct ff_effect *effects;
	struct file *effect_owners[];
};

int input_ff_create(struct input_dev *dev, int max_effects);
void input_ff_destroy(struct input_dev *dev);

int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);

int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);

int input_ff_create_memless(struct input_dev *dev, void *data,
		int (*play_effect)(struct input_dev *, void *, struct ff_effect *));

#endif
#endif

 #define KEY_BACK 158 /* AC Back */

           KEY   CODE

这里的值跟上面的XX.kl文件对应

fraemworks/base/core/java/android/view/KeyEvent.java

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.method.MetaKeyKeyListener;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.KeyCharacterMap;
import android.view.KeyCharacterMap.KeyData;

/**
 * Object used to report key and button events.
 * 

* Each key press is described by a sequence of key events. A key press * starts with a key event with {@link #ACTION_DOWN}. If the key is held * sufficiently long that it repeats, then the initial down is followed * additional key events with {@link #ACTION_DOWN} and a non-zero value for * {@link #getRepeatCount()}. The last key event is a {@link #ACTION_UP} * for the key up. If the key press is canceled, the key up event will have the * {@link #FLAG_CANCELED} flag set. *

* Key events are generally accompanied by a key code ({@link #getKeyCode()}), * scan code ({@link #getScanCode()}) and meta state ({@link #getMetaState()}). * Key code constants are defined in this class. Scan code constants are raw * device-specific codes obtained from the OS and so are not generally meaningful * to applications unless interpreted using the {@link KeyCharacterMap}. * Meta states describe the pressed state of key modifiers * such as {@link #META_SHIFT_ON} or {@link #META_ALT_ON}. *

* Key codes typically correspond one-to-one with individual keys on an input device. * Many keys and key combinations serve quite different functions on different * input devices so care must be taken when interpreting them. Always use the * {@link KeyCharacterMap} associated with the input device when mapping keys * to characters. Be aware that there may be multiple key input devices active * at the same time and each will have its own key character map. *

* As soft input methods can use multiple and inventive ways of inputting text, * there is no guarantee that any key press on a soft keyboard will generate a key * event: this is left to the IME's discretion, and in fact sending such events is * discouraged. You should never rely on receiving KeyEvents for any key on a soft * input method. In particular, the default software keyboard will never send any * key event to any application targetting Jelly Bean or later, and will only send * events for some presses of the delete and return keys to applications targetting * Ice Cream Sandwich or earlier. Be aware that other software input methods may * never send key events regardless of the version. Consider using editor actions * like {@link android.view.inputmethod.EditorInfo#IME_ACTION_DONE} if you need * specific interaction with the software keyboard, as it gives more visibility to * the user as to how your application will react to key presses. *

* When interacting with an IME, the framework may deliver key events * with the special action {@link #ACTION_MULTIPLE} that either specifies * that single repeated key code or a sequence of characters to insert. *

* In general, the framework cannot guarantee that the key events it delivers * to a view always constitute complete key sequences since some events may be dropped * or modified by containing views before they are delivered. The view implementation * should be prepared to handle {@link #FLAG_CANCELED} and should tolerate anomalous * situations such as receiving a new {@link #ACTION_DOWN} without first having * received an {@link #ACTION_UP} for the prior key press. *

* Refer to {@link InputDevice} for more information about how different kinds of * input devices and sources represent keys and buttons. *

*/ public class KeyEvent extends InputEvent implements Parcelable { /** Key code constant: Unknown key code. */ public static final int KEYCODE_UNKNOWN = 0; /** Key code constant: 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. */ public static final int KEYCODE_SOFT_LEFT = 1; /** Key code constant: 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. */ public static final int KEYCODE_SOFT_RIGHT = 2; /** Key code constant: Home key. * This key is handled by the framework and is never delivered to applications. */ public static final int KEYCODE_HOME = 3; /** Key code constant: Back key. */ public static final int KEYCODE_BACK = 4; /** Key code constant: Call key. */ public static final int KEYCODE_CALL = 5; /** Key code constant: End Call key. */ public static final int KEYCODE_ENDCALL = 6; /** Key code constant: '0' key. */ public static final int KEYCODE_0 = 7; /** Key code constant: '1' key. */ public static final int KEYCODE_1 = 8; /** Key code constant: '2' key. */ public static final int KEYCODE_2 = 9; /** Key code constant: '3' key. */ public static final int KEYCODE_3 = 10; /** Key code constant: '4' key. */ public static final int KEYCODE_4 = 11; /** Key code constant: '5' key. */ public static final int KEYCODE_5 = 12; /** Key code constant: '6' key. */ public static final int KEYCODE_6 = 13; /** Key code constant: '7' key. */ public static final int KEYCODE_7 = 14; /** Key code constant: '8' key. */ public static final int KEYCODE_8 = 15; /** Key code constant: '9' key. */ public static final int KEYCODE_9 = 16; /** Key code constant: '*' key. */ public static final int KEYCODE_STAR = 17; /** Key code constant: '#' key. */ public static final int KEYCODE_POUND = 18; /** Key code constant: Directional Pad Up key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_UP = 19; /** Key code constant: Directional Pad Down key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_DOWN = 20; /** Key code constant: Directional Pad Left key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_LEFT = 21; /** Key code constant: Directional Pad Right key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_RIGHT = 22; /** Key code constant: Directional Pad Center key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_CENTER = 23; /** Key code constant: Volume Up key. * Adjusts the speaker volume up. */ public static final int KEYCODE_VOLUME_UP = 24; /** Key code constant: Volume Down key. * Adjusts the speaker volume down. */ public static final int KEYCODE_VOLUME_DOWN = 25; /** Key code constant: Power key. */ public static final int KEYCODE_POWER = 26; /** Key code constant: Camera key. * Used to launch a camera application or take pictures. */ public static final int KEYCODE_CAMERA = 27; /** Key code constant: Clear key. */ public static final int KEYCODE_CLEAR = 28; /** Key code constant: 'A' key. */ public static final int KEYCODE_A = 29; /** Key code constant: 'B' key. */ public static final int KEYCODE_B = 30; /** Key code constant: 'C' key. */ public static final int KEYCODE_C = 31; /** Key code constant: 'D' key. */ public static final int KEYCODE_D = 32; /** Key code constant: 'E' key. */ public static final int KEYCODE_E = 33; /** Key code constant: 'F' key. */ public static final int KEYCODE_F = 34; /** Key code constant: 'G' key. */ public static final int KEYCODE_G = 35; /** Key code constant: 'H' key. */ public static final int KEYCODE_H = 36; /** Key code constant: 'I' key. */ public static final int KEYCODE_I = 37; /** Key code constant: 'J' key. */ public static final int KEYCODE_J = 38; /** Key code constant: 'K' key. */ public static final int KEYCODE_K = 39; /** Key code constant: 'L' key. */ public static final int KEYCODE_L = 40; /** Key code constant: 'M' key. */ public static final int KEYCODE_M = 41; /** Key code constant: 'N' key. */ public static final int KEYCODE_N = 42; /** Key code constant: 'O' key. */ public static final int KEYCODE_O = 43; /** Key code constant: 'P' key. */ public static final int KEYCODE_P = 44; /** Key code constant: 'Q' key. */ public static final int KEYCODE_Q = 45; /** Key code constant: 'R' key. */ public static final int KEYCODE_R = 46; /** Key code constant: 'S' key. */ public static final int KEYCODE_S = 47; /** Key code constant: 'T' key. */ public static final int KEYCODE_T = 48; /** Key code constant: 'U' key. */ public static final int KEYCODE_U = 49; /** Key code constant: 'V' key. */ public static final int KEYCODE_V = 50; /** Key code constant: 'W' key. */ public static final int KEYCODE_W = 51; /** Key code constant: 'X' key. */ public static final int KEYCODE_X = 52; /** Key code constant: 'Y' key. */ public static final int KEYCODE_Y = 53; /** Key code constant: 'Z' key. */ public static final int KEYCODE_Z = 54; /** Key code constant: ',' key. */ public static final int KEYCODE_COMMA = 55; /** Key code constant: '.' key. */ public static final int KEYCODE_PERIOD = 56; /** Key code constant: Left Alt modifier key. */ public static final int KEYCODE_ALT_LEFT = 57; /** Key code constant: Right Alt modifier key. */ public static final int KEYCODE_ALT_RIGHT = 58; /** Key code constant: Left Shift modifier key. */ public static final int KEYCODE_SHIFT_LEFT = 59; /** Key code constant: Right Shift modifier key. */ public static final int KEYCODE_SHIFT_RIGHT = 60; /** Key code constant: Tab key. */ public static final int KEYCODE_TAB = 61; /** Key code constant: Space key. */ public static final int KEYCODE_SPACE = 62; /** Key code constant: Symbol modifier key. * Used to enter alternate symbols. */ public static final int KEYCODE_SYM = 63; /** Key code constant: Explorer special function key. * Used to launch a browser application. */ public static final int KEYCODE_EXPLORER = 64; /** Key code constant: Envelope special function key. * Used to launch a mail application. */ public static final int KEYCODE_ENVELOPE = 65; /** Key code constant: Enter key. */ public static final int KEYCODE_ENTER = 66; /** Key code constant: Backspace key. * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */ public static final int KEYCODE_DEL = 67; /** Key code constant: '`' (backtick) key. */ public static final int KEYCODE_GRAVE = 68; /** Key code constant: '-'. */ public static final int KEYCODE_MINUS = 69; /** Key code constant: '=' key. */ public static final int KEYCODE_EQUALS = 70; /** Key code constant: '[' key. */ public static final int KEYCODE_LEFT_BRACKET = 71; /** Key code constant: ']' key. */ public static final int KEYCODE_RIGHT_BRACKET = 72; /** Key code constant: '\' key. */ public static final int KEYCODE_BACKSLASH = 73; /** Key code constant: ';' key. */ public static final int KEYCODE_SEMICOLON = 74; /** Key code constant: ''' (apostrophe) key. */ public static final int KEYCODE_APOSTROPHE = 75; /** Key code constant: '/' key. */ public static final int KEYCODE_SLASH = 76; /** Key code constant: '@' key. */ public static final int KEYCODE_AT = 77; /** Key code constant: 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}. */ public static final int KEYCODE_NUM = 78; /** Key code constant: Headset Hook key. * Used to hang up calls and stop media. */ public static final int KEYCODE_HEADSETHOOK = 79; /** Key code constant: Camera Focus key. * Used to focus the camera. */ public static final int KEYCODE_FOCUS = 80; // *Camera* focus /** Key code constant: '+' key. */ public static final int KEYCODE_PLUS = 81; /** Key code constant: Menu key. */ public static final int KEYCODE_MENU = 82; /** Key code constant: Notification key. */ public static final int KEYCODE_NOTIFICATION = 83; /** Key code constant: Search key. */ public static final int KEYCODE_SEARCH = 84; /** Key code constant: Play/Pause media key. */ public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85; /** Key code constant: Stop media key. */ public static final int KEYCODE_MEDIA_STOP = 86; /** Key code constant: Play Next media key. */ public static final int KEYCODE_MEDIA_NEXT = 87; /** Key code constant: Play Previous media key. */ public static final int KEYCODE_MEDIA_PREVIOUS = 88; /** Key code constant: Rewind media key. */ public static final int KEYCODE_MEDIA_REWIND = 89; /** Key code constant: Fast Forward media key. */ public static final int KEYCODE_MEDIA_FAST_FORWARD = 90; /** Key code constant: Mute key. * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */ public static final int KEYCODE_MUTE = 91; /** Key code constant: Page Up key. */ public static final int KEYCODE_PAGE_UP = 92; /** Key code constant: Page Down key. */ public static final int KEYCODE_PAGE_DOWN = 93; /** Key code constant: Picture Symbols modifier key. * Used to switch symbol sets (Emoji, Kao-moji). */ public static final int KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji) /** Key code constant: Switch Charset modifier key. * Used to switch character sets (Kanji, Katakana). */ public static final int KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana) /** Key code constant: A Button key. * On a game controller, the A button should be either the button labeled A * or the first button on the upper row of controller buttons. */ public static final int KEYCODE_BUTTON_A = 96; /** Key code constant: B Button key. * On a game controller, the B button should be either the button labeled B * or the second button on the upper row of controller buttons. */ public static final int KEYCODE_BUTTON_B = 97; /** Key code constant: C Button key. * On a game controller, the C button should be either the button labeled C * or the third button on the upper row of controller buttons. */ public static final int KEYCODE_BUTTON_C = 98; /** Key code constant: X Button key. * On a game controller, the X button should be either the button labeled X * or the first button on the lower row of controller buttons. */ public static final int KEYCODE_BUTTON_X = 99; /** Key code constant: Y Button key. * On a game controller, the Y button should be either the button labeled Y * or the second button on the lower row of controller buttons. */ public static final int KEYCODE_BUTTON_Y = 100; /** Key code constant: Z Button key. * On a game controller, the Z button should be either the button labeled Z * or the third button on the lower row of controller buttons. */ public static final int KEYCODE_BUTTON_Z = 101; /** Key code constant: 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. */ public static final int KEYCODE_BUTTON_L1 = 102; /** Key code constant: 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. */ public static final int KEYCODE_BUTTON_R1 = 103; /** Key code constant: L2 Button key. * On a game controller, the L2 button should be either the button labeled L2 * or the bottom left trigger button. */ public static final int KEYCODE_BUTTON_L2 = 104; /** Key code constant: R2 Button key. * On a game controller, the R2 button should be either the button labeled R2 * or the bottom right trigger button. */ public static final int KEYCODE_BUTTON_R2 = 105; /** Key code constant: Left Thumb Button key. * On a game controller, the left thumb button indicates that the left (or only) * joystick is pressed. */ public static final int KEYCODE_BUTTON_THUMBL = 106; /** Key code constant: Right Thumb Button key. * On a game controller, the right thumb button indicates that the right * joystick is pressed. */ public static final int KEYCODE_BUTTON_THUMBR = 107; /** Key code constant: Start Button key. * On a game controller, the button labeled Start. */ public static final int KEYCODE_BUTTON_START = 108; /** Key code constant: Select Button key. * On a game controller, the button labeled Select. */ public static final int KEYCODE_BUTTON_SELECT = 109; /** Key code constant: Mode Button key. * On a game controller, the button labeled Mode. */ public static final int KEYCODE_BUTTON_MODE = 110; /** Key code constant: Escape key. */ public static final int KEYCODE_ESCAPE = 111; /** Key code constant: Forward Delete key. * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */ public static final int KEYCODE_FORWARD_DEL = 112; /** Key code constant: Left Control modifier key. */ public static final int KEYCODE_CTRL_LEFT = 113; /** Key code constant: Right Control modifier key. */ public static final int KEYCODE_CTRL_RIGHT = 114; /** Key code constant: Caps Lock key. */ public static final int KEYCODE_CAPS_LOCK = 115; /** Key code constant: Scroll Lock key. */ public static final int KEYCODE_SCROLL_LOCK = 116; /** Key code constant: Left Meta modifier key. */ public static final int KEYCODE_META_LEFT = 117; /** Key code constant: Right Meta modifier key. */ public static final int KEYCODE_META_RIGHT = 118; /** Key code constant: Function modifier key. */ public static final int KEYCODE_FUNCTION = 119; /** Key code constant: System Request / Print Screen key. */ public static final int KEYCODE_SYSRQ = 120; /** Key code constant: Break / Pause key. */ public static final int KEYCODE_BREAK = 121; /** Key code constant: Home Movement key. * Used for scrolling or moving the cursor around to the start of a line * or to the top of a list. */ public static final int KEYCODE_MOVE_HOME = 122; /** Key code constant: End Movement key. * Used for scrolling or moving the cursor around to the end of a line * or to the bottom of a list. */ public static final int KEYCODE_MOVE_END = 123; /** Key code constant: Insert key. * Toggles insert / overwrite edit mode. */ public static final int KEYCODE_INSERT = 124; /** Key code constant: Forward key. * Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */ public static final int KEYCODE_FORWARD = 125; /** Key code constant: Play media key. */ public static final int KEYCODE_MEDIA_PLAY = 126; /** Key code constant: Pause media key. */ public static final int KEYCODE_MEDIA_PAUSE = 127; /** Key code constant: Close media key. * May be used to close a CD tray, for example. */ public static final int KEYCODE_MEDIA_CLOSE = 128; /** Key code constant: Eject media key. * May be used to eject a CD tray, for example. */ public static final int KEYCODE_MEDIA_EJECT = 129; /** Key code constant: Record media key. */ public static final int KEYCODE_MEDIA_RECORD = 130; /** Key code constant: F1 key. */ public static final int KEYCODE_F1 = 131; /** Key code constant: F2 key. */ public static final int KEYCODE_F2 = 132; /** Key code constant: F3 key. */ public static final int KEYCODE_F3 = 133; /** Key code constant: F4 key. */ public static final int KEYCODE_F4 = 134; /** Key code constant: F5 key. */ public static final int KEYCODE_F5 = 135; /** Key code constant: F6 key. */ public static final int KEYCODE_F6 = 136; /** Key code constant: F7 key. */ public static final int KEYCODE_F7 = 137; /** Key code constant: F8 key. */ public static final int KEYCODE_F8 = 138; /** Key code constant: F9 key. */ public static final int KEYCODE_F9 = 139; /** Key code constant: F10 key. */ public static final int KEYCODE_F10 = 140; /** Key code constant: F11 key. */ public static final int KEYCODE_F11 = 141; /** Key code constant: F12 key. */ public static final int KEYCODE_F12 = 142; /** Key code constant: 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. */ public static final int KEYCODE_NUM_LOCK = 143; /** Key code constant: Numeric keypad '0' key. */ public static final int KEYCODE_NUMPAD_0 = 144; /** Key code constant: Numeric keypad '1' key. */ public static final int KEYCODE_NUMPAD_1 = 145; /** Key code constant: Numeric keypad '2' key. */ public static final int KEYCODE_NUMPAD_2 = 146; /** Key code constant: Numeric keypad '3' key. */ public static final int KEYCODE_NUMPAD_3 = 147; /** Key code constant: Numeric keypad '4' key. */ public static final int KEYCODE_NUMPAD_4 = 148; /** Key code constant: Numeric keypad '5' key. */ public static final int KEYCODE_NUMPAD_5 = 149; /** Key code constant: Numeric keypad '6' key. */ public static final int KEYCODE_NUMPAD_6 = 150; /** Key code constant: Numeric keypad '7' key. */ public static final int KEYCODE_NUMPAD_7 = 151; /** Key code constant: Numeric keypad '8' key. */ public static final int KEYCODE_NUMPAD_8 = 152; /** Key code constant: Numeric keypad '9' key. */ public static final int KEYCODE_NUMPAD_9 = 153; /** Key code constant: Numeric keypad '/' key (for division). */ public static final int KEYCODE_NUMPAD_DIVIDE = 154; /** Key code constant: Numeric keypad '*' key (for multiplication). */ public static final int KEYCODE_NUMPAD_MULTIPLY = 155; /** Key code constant: Numeric keypad '-' key (for subtraction). */ public static final int KEYCODE_NUMPAD_SUBTRACT = 156; /** Key code constant: Numeric keypad '+' key (for addition). */ public static final int KEYCODE_NUMPAD_ADD = 157; /** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */ public static final int KEYCODE_NUMPAD_DOT = 158; /** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */ public static final int KEYCODE_NUMPAD_COMMA = 159; /** Key code constant: Numeric keypad Enter key. */ public static final int KEYCODE_NUMPAD_ENTER = 160; /** Key code constant: Numeric keypad '=' key. */ public static final int KEYCODE_NUMPAD_EQUALS = 161; /** Key code constant: Numeric keypad '(' key. */ public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162; /** Key code constant: Numeric keypad ')' key. */ public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163; /** Key code constant: 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. */ public static final int KEYCODE_VOLUME_MUTE = 164; /** Key code constant: Info key. * Common on TV remotes to show additional information related to what is * currently being viewed. */ public static final int KEYCODE_INFO = 165; /** Key code constant: Channel up key. * On TV remotes, increments the television channel. */ public static final int KEYCODE_CHANNEL_UP = 166; /** Key code constant: Channel down key. * On TV remotes, decrements the television channel. */ public static final int KEYCODE_CHANNEL_DOWN = 167; /** Key code constant: Zoom in key. */ public static final int KEYCODE_ZOOM_IN = 168; /** Key code constant: Zoom out key. */ public static final int KEYCODE_ZOOM_OUT = 169; /** Key code constant: TV key. * On TV remotes, switches to viewing live TV. */ public static final int KEYCODE_TV = 170; /** Key code constant: Window key. * On TV remotes, toggles picture-in-picture mode or other windowing functions. */ public static final int KEYCODE_WINDOW = 171; /** Key code constant: Guide key. * On TV remotes, shows a programming guide. */ public static final int KEYCODE_GUIDE = 172; /** Key code constant: DVR key. * On some TV remotes, switches to a DVR mode for recorded shows. */ public static final int KEYCODE_DVR = 173; /** Key code constant: Bookmark key. * On some TV remotes, bookmarks content or web pages. */ public static final int KEYCODE_BOOKMARK = 174; /** Key code constant: Toggle captions key. * Switches the mode for closed-captioning text, for example during television shows. */ public static final int KEYCODE_CAPTIONS = 175; /** Key code constant: Settings key. * Starts the system settings activity. */ public static final int KEYCODE_SETTINGS = 176; /** Key code constant: TV power key. * On TV remotes, toggles the power on a television screen. */ public static final int KEYCODE_TV_POWER = 177; /** Key code constant: TV input key. * On TV remotes, switches the input on a television screen. */ public static final int KEYCODE_TV_INPUT = 178; /** Key code constant: Set-top-box power key. * On TV remotes, toggles the power on an external Set-top-box. */ public static final int KEYCODE_STB_POWER = 179; /** Key code constant: Set-top-box input key. * On TV remotes, switches the input mode on an external Set-top-box. */ public static final int KEYCODE_STB_INPUT = 180; /** Key code constant: A/V Receiver power key. * On TV remotes, toggles the power on an external A/V Receiver. */ public static final int KEYCODE_AVR_POWER = 181; /** Key code constant: A/V Receiver input key. * On TV remotes, switches the input mode on an external A/V Receiver. */ public static final int KEYCODE_AVR_INPUT = 182; /** Key code constant: Red "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ public static final int KEYCODE_PROG_RED = 183; /** Key code constant: Green "programmable" key. * On TV remotes, actsas a contextual/programmable key. */ public static final int KEYCODE_PROG_GREEN = 184; /** Key code constant: Yellow "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ public static final int KEYCODE_PROG_YELLOW = 185; /** Key code constant: Blue "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ public static final int KEYCODE_PROG_BLUE = 186; /** Key code constant: App switch key. * Should bring up the application switcher dialog. */ public static final int KEYCODE_APP_SWITCH = 187; /** Key code constant: Generic Game Pad Button #1.*/ public static final int KEYCODE_BUTTON_1 = 188; /** Key code constant: Generic Game Pad Button #2.*/ public static final int KEYCODE_BUTTON_2 = 189; /** Key code constant: Generic Game Pad Button #3.*/ public static final int KEYCODE_BUTTON_3 = 190; /** Key code constant: Generic Game Pad Button #4.*/ public static final int KEYCODE_BUTTON_4 = 191; /** Key code constant: Generic Game Pad Button #5.*/ public static final int KEYCODE_BUTTON_5 = 192; /** Key code constant: Generic Game Pad Button #6.*/ public static final int KEYCODE_BUTTON_6 = 193; /** Key code constant: Generic Game Pad Button #7.*/ public static final int KEYCODE_BUTTON_7 = 194; /** Key code constant: Generic Game Pad Button #8.*/ public static final int KEYCODE_BUTTON_8 = 195; /** Key code constant: Generic Game Pad Button #9.*/ public static final int KEYCODE_BUTTON_9 = 196; /** Key code constant: Generic Game Pad Button #10.*/ public static final int KEYCODE_BUTTON_10 = 197; /** Key code constant: Generic Game Pad Button #11.*/ public static final int KEYCODE_BUTTON_11 = 198; /** Key code constant: Generic Game Pad Button #12.*/ public static final int KEYCODE_BUTTON_12 = 199; /** Key code constant: Generic Game Pad Button #13.*/ public static final int KEYCODE_BUTTON_13 = 200; /** Key code constant: Generic Game Pad Button #14.*/ public static final int KEYCODE_BUTTON_14 = 201; /** Key code constant: Generic Game Pad Button #15.*/ public static final int KEYCODE_BUTTON_15 = 202; /** Key code constant: Generic Game Pad Button #16.*/ public static final int KEYCODE_BUTTON_16 = 203; /** Key code constant: 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. */ public static final int KEYCODE_LANGUAGE_SWITCH = 204; /** Key code constant: 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. */ public static final int KEYCODE_MANNER_MODE = 205; /** Key code constant: 3D Mode key. * Toggles the display between 2D and 3D mode. */ public static final int KEYCODE_3D_MODE = 206; /** Key code constant: Contacts special function key. * Used to launch an address book application. */ public static final int KEYCODE_CONTACTS = 207; /** Key code constant: Calendar special function key. * Used to launch a calendar application. */ public static final int KEYCODE_CALENDAR = 208; /** Key code constant: Music special function key. * Used to launch a music player application. */ public static final int KEYCODE_MUSIC = 209; /** Key code constant: Calculator special function key. * Used to launch a calculator application. */ public static final int KEYCODE_CALCULATOR = 210; /** Key code constant: Japanese full-width / half-width key. */ public static final int KEYCODE_ZENKAKU_HANKAKU = 211; /** Key code constant: Japanese alphanumeric key. */ public static final int KEYCODE_EISU = 212; /** Key code constant: Japanese non-conversion key. */ public static final int KEYCODE_MUHENKAN = 213; /** Key code constant: Japanese conversion key. */ public static final int KEYCODE_HENKAN = 214; /** Key code constant: Japanese katakana / hiragana key. */ public static final int KEYCODE_KATAKANA_HIRAGANA = 215; /** Key code constant: Japanese Yen key. */ public static final int KEYCODE_YEN = 216; /** Key code constant: Japanese Ro key. */ public static final int KEYCODE_RO = 217; /** Key code constant: Japanese kana key. */ public static final int KEYCODE_KANA = 218; /** Key code constant: Assist key. * Launches the global assist activity. Not delivered to applications. */ public static final int KEYCODE_ASSIST = 219; private static final int LAST_KEYCODE = KEYCODE_ASSIST; // NOTE: If you add a new keycode here you must also add it to: // isSystem() // native/include/android/keycodes.h // frameworks/base/include/ui/KeycodeLabels.h // external/webkit/WebKit/android/plugins/ANPKeyCodes.h // frameworks/base/core/res/res/values/attrs.xml // emulator? // LAST_KEYCODE // KEYCODE_SYMBOLIC_NAMES // // Also Android currently does not reserve code ranges for vendor- // specific key codes. If you have new key codes to have, you // MUST contribute a patch to the open source project to define // those new codes. This is intended to maintain a consistent // set of key code definitions across all Android devices. // Symbolic names of all key codes. private static final SparseArray KEYCODE_SYMBOLIC_NAMES = new SparseArray(); private static void populateKeycodeSymbolicNames() { SparseArray names = KEYCODE_SYMBOLIC_NAMES; names.append(KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN"); names.append(KEYCODE_SOFT_LEFT, "KEYCODE_SOFT_LEFT"); names.append(KEYCODE_SOFT_RIGHT, "KEYCODE_SOFT_RIGHT"); names.append(KEYCODE_HOME, "KEYCODE_HOME"); names.append(KEYCODE_BACK, "KEYCODE_BACK"); names.append(KEYCODE_CALL, "KEYCODE_CALL"); names.append(KEYCODE_ENDCALL, "KEYCODE_ENDCALL"); names.append(KEYCODE_0, "KEYCODE_0"); names.append(KEYCODE_1, "KEYCODE_1"); names.append(KEYCODE_2, "KEYCODE_2"); names.append(KEYCODE_3, "KEYCODE_3"); names.append(KEYCODE_4, "KEYCODE_4"); names.append(KEYCODE_5, "KEYCODE_5"); names.append(KEYCODE_6, "KEYCODE_6"); names.append(KEYCODE_7, "KEYCODE_7"); names.append(KEYCODE_8, "KEYCODE_8"); names.append(KEYCODE_9, "KEYCODE_9"); names.append(KEYCODE_STAR, "KEYCODE_STAR"); names.append(KEYCODE_POUND, "KEYCODE_POUND"); names.append(KEYCODE_DPAD_UP, "KEYCODE_DPAD_UP"); names.append(KEYCODE_DPAD_DOWN, "KEYCODE_DPAD_DOWN"); names.append(KEYCODE_DPAD_LEFT, "KEYCODE_DPAD_LEFT"); names.append(KEYCODE_DPAD_RIGHT, "KEYCODE_DPAD_RIGHT"); names.append(KEYCODE_DPAD_CENTER, "KEYCODE_DPAD_CENTER"); names.append(KEYCODE_VOLUME_UP, "KEYCODE_VOLUME_UP"); names.append(KEYCODE_VOLUME_DOWN, "KEYCODE_VOLUME_DOWN"); names.append(KEYCODE_POWER, "KEYCODE_POWER"); names.append(KEYCODE_CAMERA, "KEYCODE_CAMERA"); names.append(KEYCODE_CLEAR, "KEYCODE_CLEAR"); names.append(KEYCODE_A, "KEYCODE_A"); names.append(KEYCODE_B, "KEYCODE_B"); names.append(KEYCODE_C, "KEYCODE_C"); names.append(KEYCODE_D, "KEYCODE_D"); names.append(KEYCODE_E, "KEYCODE_E"); names.append(KEYCODE_F, "KEYCODE_F"); names.append(KEYCODE_G, "KEYCODE_G"); names.append(KEYCODE_H, "KEYCODE_H"); names.append(KEYCODE_I, "KEYCODE_I"); names.append(KEYCODE_J, "KEYCODE_J"); names.append(KEYCODE_K, "KEYCODE_K"); names.append(KEYCODE_L, "KEYCODE_L"); names.append(KEYCODE_M, "KEYCODE_M"); names.append(KEYCODE_N, "KEYCODE_N"); names.append(KEYCODE_O, "KEYCODE_O"); names.append(KEYCODE_P, "KEYCODE_P"); names.append(KEYCODE_Q, "KEYCODE_Q"); names.append(KEYCODE_R, "KEYCODE_R"); names.append(KEYCODE_S, "KEYCODE_S"); names.append(KEYCODE_T, "KEYCODE_T"); names.append(KEYCODE_U, "KEYCODE_U"); names.append(KEYCODE_V, "KEYCODE_V"); names.append(KEYCODE_W, "KEYCODE_W"); names.append(KEYCODE_X, "KEYCODE_X"); names.append(KEYCODE_Y, "KEYCODE_Y"); names.append(KEYCODE_Z, "KEYCODE_Z"); names.append(KEYCODE_COMMA, "KEYCODE_COMMA"); names.append(KEYCODE_PERIOD, "KEYCODE_PERIOD"); names.append(KEYCODE_ALT_LEFT, "KEYCODE_ALT_LEFT"); names.append(KEYCODE_ALT_RIGHT, "KEYCODE_ALT_RIGHT"); names.append(KEYCODE_SHIFT_LEFT, "KEYCODE_SHIFT_LEFT"); names.append(KEYCODE_SHIFT_RIGHT, "KEYCODE_SHIFT_RIGHT"); names.append(KEYCODE_TAB, "KEYCODE_TAB"); names.append(KEYCODE_SPACE, "KEYCODE_SPACE"); names.append(KEYCODE_SYM, "KEYCODE_SYM"); names.append(KEYCODE_EXPLORER, "KEYCODE_EXPLORER"); names.append(KEYCODE_ENVELOPE, "KEYCODE_ENVELOPE"); names.append(KEYCODE_ENTER, "KEYCODE_ENTER"); names.append(KEYCODE_DEL, "KEYCODE_DEL"); names.append(KEYCODE_GRAVE, "KEYCODE_GRAVE"); names.append(KEYCODE_MINUS, "KEYCODE_MINUS"); names.append(KEYCODE_EQUALS, "KEYCODE_EQUALS"); names.append(KEYCODE_LEFT_BRACKET, "KEYCODE_LEFT_BRACKET"); names.append(KEYCODE_RIGHT_BRACKET, "KEYCODE_RIGHT_BRACKET"); names.append(KEYCODE_BACKSLASH, "KEYCODE_BACKSLASH"); names.append(KEYCODE_SEMICOLON, "KEYCODE_SEMICOLON"); names.append(KEYCODE_APOSTROPHE, "KEYCODE_APOSTROPHE"); names.append(KEYCODE_SLASH, "KEYCODE_SLASH"); names.append(KEYCODE_AT, "KEYCODE_AT"); names.append(KEYCODE_NUM, "KEYCODE_NUM"); names.append(KEYCODE_HEADSETHOOK, "KEYCODE_HEADSETHOOK"); names.append(KEYCODE_FOCUS, "KEYCODE_FOCUS"); names.append(KEYCODE_PLUS, "KEYCODE_PLUS"); names.append(KEYCODE_MENU, "KEYCODE_MENU"); names.append(KEYCODE_NOTIFICATION, "KEYCODE_NOTIFICATION"); names.append(KEYCODE_SEARCH, "KEYCODE_SEARCH"); names.append(KEYCODE_MEDIA_PLAY_PAUSE, "KEYCODE_MEDIA_PLAY_PAUSE"); names.append(KEYCODE_MEDIA_STOP, "KEYCODE_MEDIA_STOP"); names.append(KEYCODE_MEDIA_NEXT, "KEYCODE_MEDIA_NEXT"); names.append(KEYCODE_MEDIA_PREVIOUS, "KEYCODE_MEDIA_PREVIOUS"); names.append(KEYCODE_MEDIA_REWIND, "KEYCODE_MEDIA_REWIND"); names.append(KEYCODE_MEDIA_FAST_FORWARD, "KEYCODE_MEDIA_FAST_FORWARD"); names.append(KEYCODE_MUTE, "KEYCODE_MUTE"); names.append(KEYCODE_PAGE_UP, "KEYCODE_PAGE_UP"); names.append(KEYCODE_PAGE_DOWN, "KEYCODE_PAGE_DOWN"); names.append(KEYCODE_PICTSYMBOLS, "KEYCODE_PICTSYMBOLS"); names.append(KEYCODE_SWITCH_CHARSET, "KEYCODE_SWITCH_CHARSET"); names.append(KEYCODE_BUTTON_A, "KEYCODE_BUTTON_A"); names.append(KEYCODE_BUTTON_B, "KEYCODE_BUTTON_B"); names.append(KEYCODE_BUTTON_C, "KEYCODE_BUTTON_C"); names.append(KEYCODE_BUTTON_X, "KEYCODE_BUTTON_X"); names.append(KEYCODE_BUTTON_Y, "KEYCODE_BUTTON_Y"); names.append(KEYCODE_BUTTON_Z, "KEYCODE_BUTTON_Z"); names.append(KEYCODE_BUTTON_L1, "KEYCODE_BUTTON_L1"); names.append(KEYCODE_BUTTON_R1, "KEYCODE_BUTTON_R1"); names.append(KEYCODE_BUTTON_L2, "KEYCODE_BUTTON_L2"); names.append(KEYCODE_BUTTON_R2, "KEYCODE_BUTTON_R2"); names.append(KEYCODE_BUTTON_THUMBL, "KEYCODE_BUTTON_THUMBL"); names.append(KEYCODE_BUTTON_THUMBR, "KEYCODE_BUTTON_THUMBR"); names.append(KEYCODE_BUTTON_START, "KEYCODE_BUTTON_START"); names.append(KEYCODE_BUTTON_SELECT, "KEYCODE_BUTTON_SELECT"); names.append(KEYCODE_BUTTON_MODE, "KEYCODE_BUTTON_MODE"); names.append(KEYCODE_ESCAPE, "KEYCODE_ESCAPE"); names.append(KEYCODE_FORWARD_DEL, "KEYCODE_FORWARD_DEL"); names.append(KEYCODE_CTRL_LEFT, "KEYCODE_CTRL_LEFT"); names.append(KEYCODE_CTRL_RIGHT, "KEYCODE_CTRL_RIGHT"); names.append(KEYCODE_CAPS_LOCK, "KEYCODE_CAPS_LOCK"); names.append(KEYCODE_SCROLL_LOCK, "KEYCODE_SCROLL_LOCK"); names.append(KEYCODE_META_LEFT, "KEYCODE_META_LEFT"); names.append(KEYCODE_META_RIGHT, "KEYCODE_META_RIGHT"); names.append(KEYCODE_FUNCTION, "KEYCODE_FUNCTION"); names.append(KEYCODE_SYSRQ, "KEYCODE_SYSRQ"); names.append(KEYCODE_BREAK, "KEYCODE_BREAK"); names.append(KEYCODE_MOVE_HOME, "KEYCODE_MOVE_HOME"); names.append(KEYCODE_MOVE_END, "KEYCODE_MOVE_END"); names.append(KEYCODE_INSERT, "KEYCODE_INSERT"); names.append(KEYCODE_FORWARD, "KEYCODE_FORWARD"); names.append(KEYCODE_MEDIA_PLAY, "KEYCODE_MEDIA_PLAY"); names.append(KEYCODE_MEDIA_PAUSE, "KEYCODE_MEDIA_PAUSE"); names.append(KEYCODE_MEDIA_CLOSE, "KEYCODE_MEDIA_CLOSE"); names.append(KEYCODE_MEDIA_EJECT, "KEYCODE_MEDIA_EJECT"); names.append(KEYCODE_MEDIA_RECORD, "KEYCODE_MEDIA_RECORD"); names.append(KEYCODE_F1, "KEYCODE_F1"); names.append(KEYCODE_F2, "KEYCODE_F2"); names.append(KEYCODE_F3, "KEYCODE_F3"); names.append(KEYCODE_F4, "KEYCODE_F4"); names.append(KEYCODE_F5, "KEYCODE_F5"); names.append(KEYCODE_F6, "KEYCODE_F6"); names.append(KEYCODE_F7, "KEYCODE_F7"); names.append(KEYCODE_F8, "KEYCODE_F8"); names.append(KEYCODE_F9, "KEYCODE_F9"); names.append(KEYCODE_F10, "KEYCODE_F10"); names.append(KEYCODE_F11, "KEYCODE_F11"); names.append(KEYCODE_F12, "KEYCODE_F12"); names.append(KEYCODE_NUM_LOCK, "KEYCODE_NUM_LOCK"); names.append(KEYCODE_NUMPAD_0, "KEYCODE_NUMPAD_0"); names.append(KEYCODE_NUMPAD_1, "KEYCODE_NUMPAD_1"); names.append(KEYCODE_NUMPAD_2, "KEYCODE_NUMPAD_2"); names.append(KEYCODE_NUMPAD_3, "KEYCODE_NUMPAD_3"); names.append(KEYCODE_NUMPAD_4, "KEYCODE_NUMPAD_4"); names.append(KEYCODE_NUMPAD_5, "KEYCODE_NUMPAD_5"); names.append(KEYCODE_NUMPAD_6, "KEYCODE_NUMPAD_6"); names.append(KEYCODE_NUMPAD_7, "KEYCODE_NUMPAD_7"); names.append(KEYCODE_NUMPAD_8, "KEYCODE_NUMPAD_8"); names.append(KEYCODE_NUMPAD_9, "KEYCODE_NUMPAD_9"); names.append(KEYCODE_NUMPAD_DIVIDE, "KEYCODE_NUMPAD_DIVIDE"); names.append(KEYCODE_NUMPAD_MULTIPLY, "KEYCODE_NUMPAD_MULTIPLY"); names.append(KEYCODE_NUMPAD_SUBTRACT, "KEYCODE_NUMPAD_SUBTRACT"); names.append(KEYCODE_NUMPAD_ADD, "KEYCODE_NUMPAD_ADD"); names.append(KEYCODE_NUMPAD_DOT, "KEYCODE_NUMPAD_DOT"); names.append(KEYCODE_NUMPAD_COMMA, "KEYCODE_NUMPAD_COMMA"); names.append(KEYCODE_NUMPAD_ENTER, "KEYCODE_NUMPAD_ENTER"); names.append(KEYCODE_NUMPAD_EQUALS, "KEYCODE_NUMPAD_EQUALS"); names.append(KEYCODE_NUMPAD_LEFT_PAREN, "KEYCODE_NUMPAD_LEFT_PAREN"); names.append(KEYCODE_NUMPAD_RIGHT_PAREN, "KEYCODE_NUMPAD_RIGHT_PAREN"); names.append(KEYCODE_VOLUME_MUTE, "KEYCODE_VOLUME_MUTE"); names.append(KEYCODE_INFO, "KEYCODE_INFO"); names.append(KEYCODE_CHANNEL_UP, "KEYCODE_CHANNEL_UP"); names.append(KEYCODE_CHANNEL_DOWN, "KEYCODE_CHANNEL_DOWN"); names.append(KEYCODE_ZOOM_IN, "KEYCODE_ZOOM_IN"); names.append(KEYCODE_ZOOM_OUT, "KEYCODE_ZOOM_OUT"); names.append(KEYCODE_TV, "KEYCODE_TV"); names.append(KEYCODE_WINDOW, "KEYCODE_WINDOW"); names.append(KEYCODE_GUIDE, "KEYCODE_GUIDE"); names.append(KEYCODE_DVR, "KEYCODE_DVR"); names.append(KEYCODE_BOOKMARK, "KEYCODE_BOOKMARK"); names.append(KEYCODE_CAPTIONS, "KEYCODE_CAPTIONS"); names.append(KEYCODE_SETTINGS, "KEYCODE_SETTINGS"); names.append(KEYCODE_TV_POWER, "KEYCODE_TV_POWER"); names.append(KEYCODE_TV_INPUT, "KEYCODE_TV_INPUT"); names.append(KEYCODE_STB_INPUT, "KEYCODE_STB_INPUT"); names.append(KEYCODE_STB_POWER, "KEYCODE_STB_POWER"); names.append(KEYCODE_AVR_POWER, "KEYCODE_AVR_POWER"); names.append(KEYCODE_AVR_INPUT, "KEYCODE_AVR_INPUT"); names.append(KEYCODE_PROG_RED, "KEYCODE_PROG_RED"); names.append(KEYCODE_PROG_GREEN, "KEYCODE_PROG_GREEN"); names.append(KEYCODE_PROG_YELLOW, "KEYCODE_PROG_YELLOW"); names.append(KEYCODE_PROG_BLUE, "KEYCODE_PROG_BLUE"); names.append(KEYCODE_APP_SWITCH, "KEYCODE_APP_SWITCH"); names.append(KEYCODE_BUTTON_1, "KEYCODE_BUTTON_1"); names.append(KEYCODE_BUTTON_2, "KEYCODE_BUTTON_2"); names.append(KEYCODE_BUTTON_3, "KEYCODE_BUTTON_3"); names.append(KEYCODE_BUTTON_4, "KEYCODE_BUTTON_4"); names.append(KEYCODE_BUTTON_5, "KEYCODE_BUTTON_5"); names.append(KEYCODE_BUTTON_6, "KEYCODE_BUTTON_6"); names.append(KEYCODE_BUTTON_7, "KEYCODE_BUTTON_7"); names.append(KEYCODE_BUTTON_8, "KEYCODE_BUTTON_8"); names.append(KEYCODE_BUTTON_9, "KEYCODE_BUTTON_9"); names.append(KEYCODE_BUTTON_10, "KEYCODE_BUTTON_10"); names.append(KEYCODE_BUTTON_11, "KEYCODE_BUTTON_11"); names.append(KEYCODE_BUTTON_12, "KEYCODE_BUTTON_12"); names.append(KEYCODE_BUTTON_13, "KEYCODE_BUTTON_13"); names.append(KEYCODE_BUTTON_14, "KEYCODE_BUTTON_14"); names.append(KEYCODE_BUTTON_15, "KEYCODE_BUTTON_15"); names.append(KEYCODE_BUTTON_16, "KEYCODE_BUTTON_16"); names.append(KEYCODE_LANGUAGE_SWITCH, "KEYCODE_LANGUAGE_SWITCH"); names.append(KEYCODE_MANNER_MODE, "KEYCODE_MANNER_MODE"); names.append(KEYCODE_3D_MODE, "KEYCODE_3D_MODE"); names.append(KEYCODE_CONTACTS, "KEYCODE_CONTACTS"); names.append(KEYCODE_CALENDAR, "KEYCODE_CALENDAR"); names.append(KEYCODE_MUSIC, "KEYCODE_MUSIC"); names.append(KEYCODE_CALCULATOR, "KEYCODE_CALCULATOR"); names.append(KEYCODE_ZENKAKU_HANKAKU, "KEYCODE_ZENKAKU_HANKAKU"); names.append(KEYCODE_EISU, "KEYCODE_EISU"); names.append(KEYCODE_MUHENKAN, "KEYCODE_MUHENKAN"); names.append(KEYCODE_HENKAN, "KEYCODE_HENKAN"); names.append(KEYCODE_KATAKANA_HIRAGANA, "KEYCODE_KATAKANA_HIRAGANA"); names.append(KEYCODE_YEN, "KEYCODE_YEN"); names.append(KEYCODE_RO, "KEYCODE_RO"); names.append(KEYCODE_KANA, "KEYCODE_KANA"); names.append(KEYCODE_ASSIST, "KEYCODE_ASSIST"); }; // Symbolic names of all metakeys in bit order from least significant to most significant. // Accordingly there are exactly 32 values in this table. private static final String[] META_SYMBOLIC_NAMES = new String[] { "META_SHIFT_ON", "META_ALT_ON", "META_SYM_ON", "META_FUNCTION_ON", "META_ALT_LEFT_ON", "META_ALT_RIGHT_ON", "META_SHIFT_LEFT_ON", "META_SHIFT_RIGHT_ON", "META_CAP_LOCKED", "META_ALT_LOCKED", "META_SYM_LOCKED", "0x00000800", "META_CTRL_ON", "META_CTRL_LEFT_ON", "META_CTRL_RIGHT_ON", "0x00008000", "META_META_ON", "META_META_LEFT_ON", "META_META_RIGHT_ON", "0x00080000", "META_CAPS_LOCK_ON", "META_NUM_LOCK_ON", "META_SCROLL_LOCK_ON", "0x00800000", "0x01000000", "0x02000000", "0x04000000", "0x08000000", "0x10000000", "0x20000000", "0x40000000", "0x80000000", }; /** * @deprecated There are now more than MAX_KEYCODE keycodes. * Use {@link #getMaxKeyCode()} instead. */ @Deprecated public static final int MAX_KEYCODE = 84; /** * {@link #getAction} value: the key has been pressed down. */ public static final int ACTION_DOWN = 0; /** * {@link #getAction} value: the key has been released. */ public static final int ACTION_UP = 1; /** * {@link #getAction} value: multiple duplicate key events have * occurred in a row, or a complex string is being delivered. If the * key code is not {#link {@link #KEYCODE_UNKNOWN} then the * {#link {@link #getRepeatCount()} method returns the number of times * the given key code should be executed. * Otherwise, if the key code is {@link #KEYCODE_UNKNOWN}, then * this is a sequence of characters as returned by {@link #getCharacters}. */ public static final int ACTION_MULTIPLE = 2; /** * SHIFT key locked in CAPS mode. * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. * @hide */ public static final int META_CAP_LOCKED = 0x100; /** * ALT key locked. * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. * @hide */ public static final int META_ALT_LOCKED = 0x200; /** * SYM key locked. * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. * @hide */ public static final int META_SYM_LOCKED = 0x400; /** * Text is in selection mode. * Reserved for use by {@link MetaKeyKeyListener} for a private unpublished constant * in its API that is currently being retained for legacy reasons. * @hide */ public static final int META_SELECTING = 0x800; /** *

This mask is used to check whether one of the ALT meta keys is pressed.

* * @see #isAltPressed() * @see #getMetaState() * @see #KEYCODE_ALT_LEFT * @see #KEYCODE_ALT_RIGHT */ public static final int META_ALT_ON = 0x02; /** *

This mask is used to check whether the left ALT meta key is pressed.

* * @see #isAltPressed() * @see #getMetaState() * @see #KEYCODE_ALT_LEFT */ public static final int META_ALT_LEFT_ON = 0x10; /** *

This mask is used to check whether the right the ALT meta key is pressed.

* * @see #isAltPressed() * @see #getMetaState() * @see #KEYCODE_ALT_RIGHT */ public static final int META_ALT_RIGHT_ON = 0x20; /** *

This mask is used to check whether one of the SHIFT meta keys is pressed.

* * @see #isShiftPressed() * @see #getMetaState() * @see #KEYCODE_SHIFT_LEFT * @see #KEYCODE_SHIFT_RIGHT */ public static final int META_SHIFT_ON = 0x1; /** *

This mask is used to check whether the left SHIFT meta key is pressed.

* * @see #isShiftPressed() * @see #getMetaState() * @see #KEYCODE_SHIFT_LEFT */ public static final int META_SHIFT_LEFT_ON = 0x40; /** *

This mask is used to check whether the right SHIFT meta key is pressed.

* * @see #isShiftPressed() * @see #getMetaState() * @see #KEYCODE_SHIFT_RIGHT */ public static final int META_SHIFT_RIGHT_ON = 0x80; /** *

This mask is used to check whether the SYM meta key is pressed.

* * @see #isSymPressed() * @see #getMetaState() */ public static final int META_SYM_ON = 0x4; /** *

This mask is used to check whether the FUNCTION meta key is pressed.

* * @see #isFunctionPressed() * @see #getMetaState() */ public static final int META_FUNCTION_ON = 0x8; /** *

This mask is used to check whether one of the CTRL meta keys is pressed.

* * @see #isCtrlPressed() * @see #getMetaState() * @see #KEYCODE_CTRL_LEFT * @see #KEYCODE_CTRL_RIGHT */ public static final int META_CTRL_ON = 0x1000; /** *

This mask is used to check whether the left CTRL meta key is pressed.

* * @see #isCtrlPressed() * @see #getMetaState() * @see #KEYCODE_CTRL_LEFT */ public static final int META_CTRL_LEFT_ON = 0x2000; /** *

This mask is used to check whether the right CTRL meta key is pressed.

* * @see #isCtrlPressed() * @see #getMetaState() * @see #KEYCODE_CTRL_RIGHT */ public static final int META_CTRL_RIGHT_ON = 0x4000; /** *

This mask is used to check whether one of the META meta keys is pressed.

* * @see #isMetaPressed() * @see #getMetaState() * @see #KEYCODE_META_LEFT * @see #KEYCODE_META_RIGHT */ public static final int META_META_ON = 0x10000; /** *

This mask is used to check whether the left META meta key is pressed.

* * @see #isMetaPressed() * @see #getMetaState() * @see #KEYCODE_META_LEFT */ public static final int META_META_LEFT_ON = 0x20000; /** *

This mask is used to check whether the right META meta key is pressed.

* * @see #isMetaPressed() * @see #getMetaState() * @see #KEYCODE_META_RIGHT */ public static final int META_META_RIGHT_ON = 0x40000; /** *

This mask is used to check whether the CAPS LOCK meta key is on.

* * @see #isCapsLockOn() * @see #getMetaState() * @see #KEYCODE_CAPS_LOCK */ public static final int META_CAPS_LOCK_ON = 0x100000; /** *

This mask is used to check whether the NUM LOCK meta key is on.

* * @see #isNumLockOn() * @see #getMetaState() * @see #KEYCODE_NUM_LOCK */ public static final int META_NUM_LOCK_ON = 0x200000; /** *

This mask is used to check whether the SCROLL LOCK meta key is on.

* * @see #isScrollLockOn() * @see #getMetaState() * @see #KEYCODE_SCROLL_LOCK */ public static final int META_SCROLL_LOCK_ON = 0x400000; /** * This mask is a combination of {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON} * and {@link #META_SHIFT_RIGHT_ON}. */ public static final int META_SHIFT_MASK = META_SHIFT_ON | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON; /** * This mask is a combination of {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON} * and {@link #META_ALT_RIGHT_ON}. */ public static final int META_ALT_MASK = META_ALT_ON | META_ALT_LEFT_ON | META_ALT_RIGHT_ON; /** * This mask is a combination of {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON} * and {@link #META_CTRL_RIGHT_ON}. */ public static final int META_CTRL_MASK = META_CTRL_ON | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON; /** * This mask is a combination of {@link #META_META_ON}, {@link #META_META_LEFT_ON} * and {@link #META_META_RIGHT_ON}. */ public static final int META_META_MASK = META_META_ON | META_META_LEFT_ON | META_META_RIGHT_ON; /** * This mask is set if the device woke because of this key event. */ public static final int FLAG_WOKE_HERE = 0x1; /** * This mask is set if the key event was generated by a software keyboard. */ public static final int FLAG_SOFT_KEYBOARD = 0x2; /** * This mask is set if we don't want the key event to cause us to leave * touch mode. */ public static final int FLAG_KEEP_TOUCH_MODE = 0x4; /** * This mask is set if an event was known to come from a trusted part * of the system. That is, the event is known to come from the user, * and could not have been spoofed by a third party component. */ public static final int FLAG_FROM_SYSTEM = 0x8; /** * This mask is used for compatibility, to identify enter keys that are * coming from an IME whose enter key has been auto-labelled "next" or * "done". This allows TextView to dispatch these as normal enter keys * for old applications, but still do the appropriate action when * receiving them. */ public static final int FLAG_EDITOR_ACTION = 0x10; /** * When associated with up key events, this indicates that the key press * has been canceled. Typically this is used with virtual touch screen * keys, where the user can slide from the virtual key area on to the * display: in that case, the application will receive a canceled up * event and should not perform the action normally associated with the * key. Note that for this to work, the application can not perform an * action for a key until it receives an up or the long press timeout has * expired. */ public static final int FLAG_CANCELED = 0x20; /** * This key event was generated by a virtual (on-screen) hard key area. * Typically this is an area of the touchscreen, outside of the regular * display, dedicated to "hardware" buttons. */ public static final int FLAG_VIRTUAL_HARD_KEY = 0x40; /** * This flag is set for the first key repeat that occurs after the * long press timeout. */ public static final int FLAG_LONG_PRESS = 0x80; /** * Set when a key event has {@link #FLAG_CANCELED} set because a long * press action was executed while it was down. */ public static final int FLAG_CANCELED_LONG_PRESS = 0x100; /** * Set for {@link #ACTION_UP} when this event's key code is still being * tracked from its initial down. That is, somebody requested that tracking * started on the key down and a long press has not caused * the tracking to be canceled. */ public static final int FLAG_TRACKING = 0x200; /** * Set when a key event has been synthesized to implement default behavior * for an event that the application did not handle. * Fallback key events are generated by unhandled trackball motions * (to emulate a directional keypad) and by certain unhandled key presses * that are declared in the key map (such as special function numeric keypad * keys when numlock is off). */ public static final int FLAG_FALLBACK = 0x400; /** * Private control to determine when an app is tracking a key sequence. * @hide */ public static final int FLAG_START_TRACKING = 0x40000000; /** * Private flag that indicates when the system has detected that this key event * may be inconsistent with respect to the sequence of previously delivered key events, * such as when a key up event is sent but the key was not down. * * @hide * @see #isTainted * @see #setTainted */ public static final int FLAG_TAINTED = 0x80000000; /** * Returns the maximum keycode. */ public static int getMaxKeyCode() { return LAST_KEYCODE; } /** * Get the character that is produced by putting accent on the character * c. * For example, getDeadChar('`', 'e') returns è. */ public static int getDeadChar(int accent, int c) { return KeyCharacterMap.getDeadChar(accent, c); } static final boolean DEBUG = false; static final String TAG = "KeyEvent"; private static final int MAX_RECYCLED = 10; private static final Object gRecyclerLock = new Object(); private static int gRecyclerUsed; private static KeyEvent gRecyclerTop; private KeyEvent mNext; private int mDeviceId; private int mSource; private int mMetaState; private int mAction; private int mKeyCode; private int mScanCode; private int mRepeatCount; private int mFlags; private long mDownTime; private long mEventTime; private String mCharacters; public interface Callback { /** * Called when a key down event has occurred. If you return true, * you can first call {@link KeyEvent#startTracking() * KeyEvent.startTracking()} to have the framework track the event * through its {@link #onKeyUp(int, KeyEvent)} and also call your * {@link #onKeyLongPress(int, KeyEvent)} if it occurs. * * @param keyCode The value in event.getKeyCode(). * @param event Description of the key event. * * @return If you handled the event, return true. If you want to allow * the event to be handled by the next receiver, return false. */ boolean onKeyDown(int keyCode, KeyEvent event); /** * Called when a long press has occurred. If you return true, * the final key up will have {@link KeyEvent#FLAG_CANCELED} and * {@link KeyEvent#FLAG_CANCELED_LONG_PRESS} set. Note that in * order to receive this callback, someone in the event change * must return true from {@link #onKeyDown} and * call {@link KeyEvent#startTracking()} on the event. * * @param keyCode The value in event.getKeyCode(). * @param event Description of the key event. * * @return If you handled the event, return true. If you want to allow * the event to be handled by the next receiver, return false. */ boolean onKeyLongPress(int keyCode, KeyEvent event); /** * Called when a key up event has occurred. * * @param keyCode The value in event.getKeyCode(). * @param event Description of the key event. * * @return If you handled the event, return true. If you want to allow * the event to be handled by the next receiver, return false. */ boolean onKeyUp(int keyCode, KeyEvent event); /** * Called when multiple down/up pairs of the same key have occurred * in a row. * * @param keyCode The value in event.getKeyCode(). * @param count Number of pairs as returned by event.getRepeatCount(). * @param event Description of the key event. * * @return If you handled the event, return true. If you want to allow * the event to be handled by the next receiver, return false. */ boolean onKeyMultiple(int keyCode, int count, KeyEvent event); } static { populateKeycodeSymbolicNames(); } private KeyEvent() { } /** * Create a new key event. * * @param action Action code: either {@link #ACTION_DOWN}, * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * @param code The key code. */ public KeyEvent(int action, int code) { mAction = action; mKeyCode = code; mRepeatCount = 0; mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; } /** * Create a new key event. * * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this key code originally went down. * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this event happened. * @param action Action code: either {@link #ACTION_DOWN}, * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * @param code The key code. * @param repeat A repeat count for down events (> 0 if this is after the * initial down) or event count for multiple events. */ public KeyEvent(long downTime, long eventTime, int action, int code, int repeat) { mDownTime = downTime; mEventTime = eventTime; mAction = action; mKeyCode = code; mRepeatCount = repeat; mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; } /** * Create a new key event. * * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this key code originally went down. * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this event happened. * @param action Action code: either {@link #ACTION_DOWN}, * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * @param code The key code. * @param repeat A repeat count for down events (> 0 if this is after the * initial down) or event count for multiple events. * @param metaState Flags indicating which meta keys are currently pressed. */ public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState) { mDownTime = downTime; mEventTime = eventTime; mAction = action; mKeyCode = code; mRepeatCount = repeat; mMetaState = metaState; mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; } /** * Create a new key event. * * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this key code originally went down. * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this event happened. * @param action Action code: either {@link #ACTION_DOWN}, * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * @param code The key code. * @param repeat A repeat count for down events (> 0 if this is after the * initial down) or event count for multiple events. * @param metaState Flags indicating which meta keys are currently pressed. * @param deviceId The device ID that generated the key event. * @param scancode Raw device scan code of the event. */ public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode) { mDownTime = downTime; mEventTime = eventTime; mAction = action; mKeyCode = code; mRepeatCount = repeat; mMetaState = metaState; mDeviceId = deviceId; mScanCode = scancode; } /** * Create a new key event. * * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this key code originally went down. * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this event happened. * @param action Action code: either {@link #ACTION_DOWN}, * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * @param code The key code. * @param repeat A repeat count for down events (> 0 if this is after the * initial down) or event count for multiple events. * @param metaState Flags indicating which meta keys are currently pressed. * @param deviceId The device ID that generated the key event. * @param scancode Raw device scan code of the event. * @param flags The flags for this key event */ public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags) { mDownTime = downTime; mEventTime = eventTime; mAction = action; mKeyCode = code; mRepeatCount = repeat; mMetaState = metaState; mDeviceId = deviceId; mScanCode = scancode; mFlags = flags; } /** * Create a new key event. * * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this key code originally went down. * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this event happened. * @param action Action code: either {@link #ACTION_DOWN}, * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * @param code The key code. * @param repeat A repeat count for down events (> 0 if this is after the * initial down) or event count for multiple events. * @param metaState Flags indicating which meta keys are currently pressed. * @param deviceId The device ID that generated the key event. * @param scancode Raw device scan code of the event. * @param flags The flags for this key event * @param source The input source such as {@link InputDevice#SOURCE_KEYBOARD}. */ public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags, int source) { mDownTime = downTime; mEventTime = eventTime; mAction = action; mKeyCode = code; mRepeatCount = repeat; mMetaState = metaState; mDeviceId = deviceId; mScanCode = scancode; mFlags = flags; mSource = source; } /** * Create a new key event for a string of characters. The key code, * action, repeat count and source will automatically be set to * {@link #KEYCODE_UNKNOWN}, {@link #ACTION_MULTIPLE}, 0, and * {@link InputDevice#SOURCE_KEYBOARD} for you. * * @param time The time (in {@link android.os.SystemClock#uptimeMillis}) * at which this event occured. * @param characters The string of characters. * @param deviceId The device ID that generated the key event. * @param flags The flags for this key event */ public KeyEvent(long time, String characters, int deviceId, int flags) { mDownTime = time; mEventTime = time; mCharacters = characters; mAction = ACTION_MULTIPLE; mKeyCode = KEYCODE_UNKNOWN; mRepeatCount = 0; mDeviceId = deviceId; mFlags = flags; mSource = InputDevice.SOURCE_KEYBOARD; } /** * Make an exact copy of an existing key event. */ public KeyEvent(KeyEvent origEvent) { mDownTime = origEvent.mDownTime; mEventTime = origEvent.mEventTime; mAction = origEvent.mAction; mKeyCode = origEvent.mKeyCode; mRepeatCount = origEvent.mRepeatCount; mMetaState = origEvent.mMetaState; mDeviceId = origEvent.mDeviceId; mSource = origEvent.mSource; mScanCode = origEvent.mScanCode; mFlags = origEvent.mFlags; mCharacters = origEvent.mCharacters; } /** * Copy an existing key event, modifying its time and repeat count. * * @deprecated Use {@link #changeTimeRepeat(KeyEvent, long, int)} * instead. * * @param origEvent The existing event to be copied. * @param eventTime The new event time * (in {@link android.os.SystemClock#uptimeMillis}) of the event. * @param newRepeat The new repeat count of the event. */ @Deprecated public KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat) { mDownTime = origEvent.mDownTime; mEventTime = eventTime; mAction = origEvent.mAction; mKeyCode = origEvent.mKeyCode; mRepeatCount = newRepeat; mMetaState = origEvent.mMetaState; mDeviceId = origEvent.mDeviceId; mSource = origEvent.mSource; mScanCode = origEvent.mScanCode; mFlags = origEvent.mFlags; mCharacters = origEvent.mCharacters; } private static KeyEvent obtain() { final KeyEvent ev; synchronized (gRecyclerLock) { ev = gRecyclerTop; if (ev == null) { return new KeyEvent(); } gRecyclerTop = ev.mNext; gRecyclerUsed -= 1; } ev.mNext = null; ev.prepareForReuse(); return ev; } /** * Obtains a (potentially recycled) key event. * * @hide */ public static KeyEvent obtain(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags, int source, String characters) { KeyEvent ev = obtain(); ev.mDownTime = downTime; ev.mEventTime = eventTime; ev.mAction = action; ev.mKeyCode = code; ev.mRepeatCount = repeat; ev.mMetaState = metaState; ev.mDeviceId = deviceId; ev.mScanCode = scancode; ev.mFlags = flags; ev.mSource = source; ev.mCharacters = characters; return ev; } /** * Obtains a (potentially recycled) copy of another key event. * * @hide */ public static KeyEvent obtain(KeyEvent other) { KeyEvent ev = obtain(); ev.mDownTime = other.mDownTime; ev.mEventTime = other.mEventTime; ev.mAction = other.mAction; ev.mKeyCode = other.mKeyCode; ev.mRepeatCount = other.mRepeatCount; ev.mMetaState = other.mMetaState; ev.mDeviceId = other.mDeviceId; ev.mScanCode = other.mScanCode; ev.mFlags = other.mFlags; ev.mSource = other.mSource; ev.mCharacters = other.mCharacters; return ev; } /** @hide */ @Override public KeyEvent copy() { return obtain(this); } /** * Recycles a key event. * Key events should only be recycled if they are owned by the system since user * code expects them to be essentially immutable, "tracking" notwithstanding. * * @hide */ @Override public final void recycle() { super.recycle(); mCharacters = null; synchronized (gRecyclerLock) { if (gRecyclerUsed < MAX_RECYCLED) { gRecyclerUsed++; mNext = gRecyclerTop; gRecyclerTop = this; } } } /** @hide */ @Override public final void recycleIfNeededAfterDispatch() { // Do nothing. } /** * Create a new key event that is the same as the given one, but whose * event time and repeat count are replaced with the given value. * * @param event The existing event to be copied. This is not modified. * @param eventTime The new event time * (in {@link android.os.SystemClock#uptimeMillis}) of the event. * @param newRepeat The new repeat count of the event. */ public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, int newRepeat) { return new KeyEvent(event, eventTime, newRepeat); } /** * Create a new key event that is the same as the given one, but whose * event time and repeat count are replaced with the given value. * * @param event The existing event to be copied. This is not modified. * @param eventTime The new event time * (in {@link android.os.SystemClock#uptimeMillis}) of the event. * @param newRepeat The new repeat count of the event. * @param newFlags New flags for the event, replacing the entire value * in the original event. */ public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, int newRepeat, int newFlags) { KeyEvent ret = new KeyEvent(event); ret.mEventTime = eventTime; ret.mRepeatCount = newRepeat; ret.mFlags = newFlags; return ret; } /** * Copy an existing key event, modifying its action. * * @param origEvent The existing event to be copied. * @param action The new action code of the event. */ private KeyEvent(KeyEvent origEvent, int action) { mDownTime = origEvent.mDownTime; mEventTime = origEvent.mEventTime; mAction = action; mKeyCode = origEvent.mKeyCode; mRepeatCount = origEvent.mRepeatCount; mMetaState = origEvent.mMetaState; mDeviceId = origEvent.mDeviceId; mSource = origEvent.mSource; mScanCode = origEvent.mScanCode; mFlags = origEvent.mFlags; // Don't copy mCharacters, since one way or the other we'll lose it // when changing the action. } /** * Create a new key event that is the same as the given one, but whose * action is replaced with the given value. * * @param event The existing event to be copied. This is not modified. * @param action The new action code of the event. */ public static KeyEvent changeAction(KeyEvent event, int action) { return new KeyEvent(event, action); } /** * Create a new key event that is the same as the given one, but whose * flags are replaced with the given value. * * @param event The existing event to be copied. This is not modified. * @param flags The new flags constant. */ public static KeyEvent changeFlags(KeyEvent event, int flags) { event = new KeyEvent(event); event.mFlags = flags; return event; } /** @hide */ @Override public final boolean isTainted() { return (mFlags & FLAG_TAINTED) != 0; } /** @hide */ @Override public final void setTainted(boolean tainted) { mFlags = tainted ? mFlags | FLAG_TAINTED : mFlags & ~FLAG_TAINTED; } /** * Don't use in new code, instead explicitly check * {@link #getAction()}. * * @return If the action is ACTION_DOWN, returns true; else false. * * @deprecated * @hide */ @Deprecated public final boolean isDown() { return mAction == ACTION_DOWN; } /** * Is this a system key? System keys can not be used for menu shortcuts. * * TODO: this information should come from a table somewhere. * TODO: should the dpad keys be here? arguably, because they also shouldn't be menu shortcuts */ public final boolean isSystem() { return native_isSystemKey(mKeyCode); } /** @hide */ public final boolean hasDefaultAction() { return native_hasDefaultAction(mKeyCode); } /** * Returns true if the specified keycode is a gamepad button. * @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}. */ public static final boolean isGamepadButton(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_BUTTON_A: case KeyEvent.KEYCODE_BUTTON_B: case KeyEvent.KEYCODE_BUTTON_C: case KeyEvent.KEYCODE_BUTTON_X: case KeyEvent.KEYCODE_BUTTON_Y: case KeyEvent.KEYCODE_BUTTON_Z: case KeyEvent.KEYCODE_BUTTON_L1: case KeyEvent.KEYCODE_BUTTON_R1: case KeyEvent.KEYCODE_BUTTON_L2: case KeyEvent.KEYCODE_BUTTON_R2: case KeyEvent.KEYCODE_BUTTON_THUMBL: case KeyEvent.KEYCODE_BUTTON_THUMBR: case KeyEvent.KEYCODE_BUTTON_START: case KeyEvent.KEYCODE_BUTTON_SELECT: case KeyEvent.KEYCODE_BUTTON_MODE: case KeyEvent.KEYCODE_BUTTON_1: case KeyEvent.KEYCODE_BUTTON_2: case KeyEvent.KEYCODE_BUTTON_3: case KeyEvent.KEYCODE_BUTTON_4: case KeyEvent.KEYCODE_BUTTON_5: case KeyEvent.KEYCODE_BUTTON_6: case KeyEvent.KEYCODE_BUTTON_7: case KeyEvent.KEYCODE_BUTTON_8: case KeyEvent.KEYCODE_BUTTON_9: case KeyEvent.KEYCODE_BUTTON_10: case KeyEvent.KEYCODE_BUTTON_11: case KeyEvent.KEYCODE_BUTTON_12: case KeyEvent.KEYCODE_BUTTON_13: case KeyEvent.KEYCODE_BUTTON_14: case KeyEvent.KEYCODE_BUTTON_15: case KeyEvent.KEYCODE_BUTTON_16: return true; default: return false; } } /** {@inheritDoc} */ @Override public final int getDeviceId() { return mDeviceId; } /** {@inheritDoc} */ @Override public final int getSource() { return mSource; } /** {@inheritDoc} */ @Override public final void setSource(int source) { mSource = source; } /** *

Returns the state of the meta keys.

* * @return an integer in which each bit set to 1 represents a pressed * meta key * * @see #isAltPressed() * @see #isShiftPressed() * @see #isSymPressed() * @see #isCtrlPressed() * @see #isMetaPressed() * @see #isFunctionPressed() * @see #isCapsLockOn() * @see #isNumLockOn() * @see #isScrollLockOn() * @see #META_ALT_ON * @see #META_ALT_LEFT_ON * @see #META_ALT_RIGHT_ON * @see #META_SHIFT_ON * @see #META_SHIFT_LEFT_ON * @see #META_SHIFT_RIGHT_ON * @see #META_SYM_ON * @see #META_FUNCTION_ON * @see #META_CTRL_ON * @see #META_CTRL_LEFT_ON * @see #META_CTRL_RIGHT_ON * @see #META_META_ON * @see #META_META_LEFT_ON * @see #META_META_RIGHT_ON * @see #META_CAPS_LOCK_ON * @see #META_NUM_LOCK_ON * @see #META_SCROLL_LOCK_ON * @see #getModifiers */ public final int getMetaState() { return mMetaState; } /** * Returns the state of the modifier keys. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, this function specifically masks out * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. *

* The value returned consists of the meta state (from {@link #getMetaState}) * normalized using {@link #normalizeMetaState(int)} and then masked with * {@link #getModifierMetaStateMask} so that only valid modifier bits are retained. *

* * @return An integer in which each bit set to 1 represents a pressed modifier key. * @see #getMetaState */ public final int getModifiers() { return normalizeMetaState(mMetaState) & META_MODIFIER_MASK; } /** * Returns the flags for this key event. * * @see #FLAG_WOKE_HERE */ public final int getFlags() { return mFlags; } // Mask of all modifier key meta states. Specifically excludes locked keys like caps lock. private static final int META_MODIFIER_MASK = META_SHIFT_ON | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON | META_ALT_ON | META_ALT_LEFT_ON | META_ALT_RIGHT_ON | META_CTRL_ON | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON | META_META_ON | META_META_LEFT_ON | META_META_RIGHT_ON | META_SYM_ON | META_FUNCTION_ON; // Mask of all lock key meta states. private static final int META_LOCK_MASK = META_CAPS_LOCK_ON | META_NUM_LOCK_ON | META_SCROLL_LOCK_ON; // Mask of all valid meta states. private static final int META_ALL_MASK = META_MODIFIER_MASK | META_LOCK_MASK; // Mask of all synthetic meta states that are reserved for API compatibility with // historical uses in MetaKeyKeyListener. private static final int META_SYNTHETIC_MASK = META_CAP_LOCKED | META_ALT_LOCKED | META_SYM_LOCKED | META_SELECTING; // Mask of all meta states that are not valid use in specifying a modifier key. // These bits are known to be used for purposes other than specifying modifiers. private static final int META_INVALID_MODIFIER_MASK = META_LOCK_MASK | META_SYNTHETIC_MASK; /** * Gets a mask that includes all valid modifier key meta state bits. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, the mask specifically excludes * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. *

* * @return The modifier meta state mask which is a combination of * {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}, {@link #META_SHIFT_RIGHT_ON}, * {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}, {@link #META_ALT_RIGHT_ON}, * {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}, {@link #META_CTRL_RIGHT_ON}, * {@link #META_META_ON}, {@link #META_META_LEFT_ON}, {@link #META_META_RIGHT_ON}, * {@link #META_SYM_ON}, {@link #META_FUNCTION_ON}. */ public static int getModifierMetaStateMask() { return META_MODIFIER_MASK; } /** * Returns true if this key code is a modifier key. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, this function return false * for those keys. *

* * @return True if the key code is one of * {@link #KEYCODE_SHIFT_LEFT} {@link #KEYCODE_SHIFT_RIGHT}, * {@link #KEYCODE_ALT_LEFT}, {@link #KEYCODE_ALT_RIGHT}, * {@link #KEYCODE_CTRL_LEFT}, {@link #KEYCODE_CTRL_RIGHT}, * {@link #KEYCODE_META_LEFT}, or {@link #KEYCODE_META_RIGHT}, * {@link #KEYCODE_SYM}, {@link #KEYCODE_NUM}, {@link #KEYCODE_FUNCTION}. */ public static boolean isModifierKey(int keyCode) { switch (keyCode) { case KEYCODE_SHIFT_LEFT: case KEYCODE_SHIFT_RIGHT: case KEYCODE_ALT_LEFT: case KEYCODE_ALT_RIGHT: case KEYCODE_CTRL_LEFT: case KEYCODE_CTRL_RIGHT: case KEYCODE_META_LEFT: case KEYCODE_META_RIGHT: case KEYCODE_SYM: case KEYCODE_NUM: case KEYCODE_FUNCTION: return true; default: return false; } } /** * Normalizes the specified meta state. *

* The meta state is normalized such that if either the left or right modifier meta state * bits are set then the result will also include the universal bit for that modifier. *

* If the specified meta state contains {@link #META_ALT_LEFT_ON} then * the result will also contain {@link #META_ALT_ON} in addition to {@link #META_ALT_LEFT_ON} * and the other bits that were specified in the input. The same is process is * performed for shift, control and meta. *

* If the specified meta state contains synthetic meta states defined by * {@link MetaKeyKeyListener}, then those states are translated here and the original * synthetic meta states are removed from the result. * {@link MetaKeyKeyListener#META_CAP_LOCKED} is translated to {@link #META_CAPS_LOCK_ON}. * {@link MetaKeyKeyListener#META_ALT_LOCKED} is translated to {@link #META_ALT_ON}. * {@link MetaKeyKeyListener#META_SYM_LOCKED} is translated to {@link #META_SYM_ON}. *

* Undefined meta state bits are removed. *

* * @param metaState The meta state. * @return The normalized meta state. */ public static int normalizeMetaState(int metaState) { if ((metaState & (META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON)) != 0) { metaState |= META_SHIFT_ON; } if ((metaState & (META_ALT_LEFT_ON | META_ALT_RIGHT_ON)) != 0) { metaState |= META_ALT_ON; } if ((metaState & (META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON)) != 0) { metaState |= META_CTRL_ON; } if ((metaState & (META_META_LEFT_ON | META_META_RIGHT_ON)) != 0) { metaState |= META_META_ON; } if ((metaState & MetaKeyKeyListener.META_CAP_LOCKED) != 0) { metaState |= META_CAPS_LOCK_ON; } if ((metaState & MetaKeyKeyListener.META_ALT_LOCKED) != 0) { metaState |= META_ALT_ON; } if ((metaState & MetaKeyKeyListener.META_SYM_LOCKED) != 0) { metaState |= META_SYM_ON; } return metaState & META_ALL_MASK; } /** * Returns true if no modifiers keys are pressed according to the specified meta state. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, this function ignores * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. *

* The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}. *

* * @param metaState The meta state to consider. * @return True if no modifier keys are pressed. * @see #hasNoModifiers() */ public static boolean metaStateHasNoModifiers(int metaState) { return (normalizeMetaState(metaState) & META_MODIFIER_MASK) == 0; } /** * Returns true if only the specified modifier keys are pressed according to * the specified meta state. Returns false if a different combination of modifier * keys are pressed. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, this function ignores * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. *

* If the specified modifier mask includes directional modifiers, such as * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the * modifier is pressed on that side. * If the specified modifier mask includes non-directional modifiers, such as * {@link #META_SHIFT_ON}, then this method ensures that the modifier * is pressed on either side. * If the specified modifier mask includes both directional and non-directional modifiers * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON}, * then this method throws an illegal argument exception. *

* * @param metaState The meta state to consider. * @param modifiers The meta state of the modifier keys to check. May be a combination * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to * ensure that no modifier keys are pressed. * @return True if only the specified modifier keys are pressed. * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers * @see #hasModifiers */ public static boolean metaStateHasModifiers(int metaState, int modifiers) { // Note: For forward compatibility, we allow the parameter to contain meta states // that we do not recognize but we explicitly disallow meta states that // are not valid modifiers. if ((modifiers & META_INVALID_MODIFIER_MASK) != 0) { throw new IllegalArgumentException("modifiers must not contain " + "META_CAPS_LOCK_ON, META_NUM_LOCK_ON, META_SCROLL_LOCK_ON, " + "META_CAP_LOCKED, META_ALT_LOCKED, META_SYM_LOCKED, " + "or META_SELECTING"); } metaState = normalizeMetaState(metaState) & META_MODIFIER_MASK; metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, META_SHIFT_ON, META_SHIFT_LEFT_ON, META_SHIFT_RIGHT_ON); metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, META_ALT_ON, META_ALT_LEFT_ON, META_ALT_RIGHT_ON); metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, META_CTRL_ON, META_CTRL_LEFT_ON, META_CTRL_RIGHT_ON); metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, META_META_ON, META_META_LEFT_ON, META_META_RIGHT_ON); return metaState == modifiers; } private static int metaStateFilterDirectionalModifiers(int metaState, int modifiers, int basic, int left, int right) { final boolean wantBasic = (modifiers & basic) != 0; final int directional = left | right; final boolean wantLeftOrRight = (modifiers & directional) != 0; if (wantBasic) { if (wantLeftOrRight) { throw new IllegalArgumentException("modifiers must not contain " + metaStateToString(basic) + " combined with " + metaStateToString(left) + " or " + metaStateToString(right)); } return metaState & ~directional; } else if (wantLeftOrRight) { return metaState & ~basic; } else { return metaState; } } /** * Returns true if no modifier keys are pressed. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, this function ignores * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. *

* The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}. *

* * @return True if no modifier keys are pressed. * @see #metaStateHasNoModifiers */ public final boolean hasNoModifiers() { return metaStateHasNoModifiers(mMetaState); } /** * Returns true if only the specified modifiers keys are pressed. * Returns false if a different combination of modifier keys are pressed. *

* For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are * not considered modifier keys. Consequently, this function ignores * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. *

* If the specified modifier mask includes directional modifiers, such as * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the * modifier is pressed on that side. * If the specified modifier mask includes non-directional modifiers, such as * {@link #META_SHIFT_ON}, then this method ensures that the modifier * is pressed on either side. * If the specified modifier mask includes both directional and non-directional modifiers * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON}, * then this method throws an illegal argument exception. *

* * @param modifiers The meta state of the modifier keys to check. May be a combination * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to * ensure that no modifier keys are pressed. * @return True if only the specified modifier keys are pressed. * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers * @see #metaStateHasModifiers */ public final boolean hasModifiers(int modifiers) { return metaStateHasModifiers(mMetaState, modifiers); } /** *

Returns the pressed state of the ALT meta key.

* * @return true if the ALT key is pressed, false otherwise * * @see #KEYCODE_ALT_LEFT * @see #KEYCODE_ALT_RIGHT * @see #META_ALT_ON */ public final boolean isAltPressed() { return (mMetaState & META_ALT_ON) != 0; } /** *

Returns the pressed state of the SHIFT meta key.

* * @return true if the SHIFT key is pressed, false otherwise * * @see #KEYCODE_SHIFT_LEFT * @see #KEYCODE_SHIFT_RIGHT * @see #META_SHIFT_ON */ public final boolean isShiftPressed() { return (mMetaState & META_SHIFT_ON) != 0; } /** *

Returns the pressed state of the SYM meta key.

* * @return true if the SYM key is pressed, false otherwise * * @see #KEYCODE_SYM * @see #META_SYM_ON */ public final boolean isSymPressed() { return (mMetaState & META_SYM_ON) != 0; } /** *

Returns the pressed state of the CTRL meta key.

* * @return true if the CTRL key is pressed, false otherwise * * @see #KEYCODE_CTRL_LEFT * @see #KEYCODE_CTRL_RIGHT * @see #META_CTRL_ON */ public final boolean isCtrlPressed() { return (mMetaState & META_CTRL_ON) != 0; } /** *

Returns the pressed state of the META meta key.

* * @return true if the META key is pressed, false otherwise * * @see #KEYCODE_META_LEFT * @see #KEYCODE_META_RIGHT * @see #META_META_ON */ public final boolean isMetaPressed() { return (mMetaState & META_META_ON) != 0; } /** *

Returns the pressed state of the FUNCTION meta key.

* * @return true if the FUNCTION key is pressed, false otherwise * * @see #KEYCODE_FUNCTION * @see #META_FUNCTION_ON */ public final boolean isFunctionPressed() { return (mMetaState & META_FUNCTION_ON) != 0; } /** *

Returns the locked state of the CAPS LOCK meta key.

* * @return true if the CAPS LOCK key is on, false otherwise * * @see #KEYCODE_CAPS_LOCK * @see #META_CAPS_LOCK_ON */ public final boolean isCapsLockOn() { return (mMetaState & META_CAPS_LOCK_ON) != 0; } /** *

Returns the locked state of the NUM LOCK meta key.

* * @return true if the NUM LOCK key is on, false otherwise * * @see #KEYCODE_NUM_LOCK * @see #META_NUM_LOCK_ON */ public final boolean isNumLockOn() { return (mMetaState & META_NUM_LOCK_ON) != 0; } /** *

Returns the locked state of the SCROLL LOCK meta key.

* * @return true if the SCROLL LOCK key is on, false otherwise * * @see #KEYCODE_SCROLL_LOCK * @see #META_SCROLL_LOCK_ON */ public final boolean isScrollLockOn() { return (mMetaState & META_SCROLL_LOCK_ON) != 0; } /** * Retrieve the action of this key event. May be either * {@link #ACTION_DOWN}, {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. * * @return The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE. */ public final int getAction() { return mAction; } /** * For {@link #ACTION_UP} events, indicates that the event has been * canceled as per {@link #FLAG_CANCELED}. */ public final boolean isCanceled() { return (mFlags&FLAG_CANCELED) != 0; } /** * Call this during {@link Callback#onKeyDown} to have the system track * the key through its final up (possibly including a long press). Note * that only one key can be tracked at a time -- if another key down * event is received while a previous one is being tracked, tracking is * stopped on the previous event. */ public final void startTracking() { mFlags |= FLAG_START_TRACKING; } /** * For {@link #ACTION_UP} events, indicates that the event is still being * tracked from its initial down event as per * {@link #FLAG_TRACKING}. */ public final boolean isTracking() { return (mFlags&FLAG_TRACKING) != 0; } /** * For {@link #ACTION_DOWN} events, indicates that the event has been * canceled as per {@link #FLAG_LONG_PRESS}. */ public final boolean isLongPress() { return (mFlags&FLAG_LONG_PRESS) != 0; } /** * Retrieve the key code of the key event. This is the physical key that * was pressed, not the Unicode character. * * @return The key code of the event. */ public final int getKeyCode() { return mKeyCode; } /** * For the special case of a {@link #ACTION_MULTIPLE} event with key * code of {@link #KEYCODE_UNKNOWN}, this is a raw string of characters * associated with the event. In all other cases it is null. * * @return Returns a String of 1 or more characters associated with * the event. */ public final String getCharacters() { return mCharacters; } /** * Retrieve the hardware key id of this key event. These values are not * reliable and vary from device to device. * * {@more} * Mostly this is here for debugging purposes. */ public final int getScanCode() { return mScanCode; } /** * Retrieve the repeat count of the event. For both key up and key down * events, this is the number of times the key has repeated with the first * down starting at 0 and counting up from there. For multiple key * events, this is the number of down/up pairs that have occurred. * * @return The number of times the key has repeated. */ public final int getRepeatCount() { return mRepeatCount; } /** * Retrieve the time of the most recent key down event, * in the {@link android.os.SystemClock#uptimeMillis} time base. If this * is a down event, this will be the same as {@link #getEventTime()}. * Note that when chording keys, this value is the down time of the * most recently pressed key, which may not be the same physical * key of this event. * * @return Returns the most recent key down time, in the * {@link android.os.SystemClock#uptimeMillis} time base */ public final long getDownTime() { return mDownTime; } /** * Retrieve the time this event occurred, * in the {@link android.os.SystemClock#uptimeMillis} time base. * * @return Returns the time this event occurred, * in the {@link android.os.SystemClock#uptimeMillis} time base. */ @Override public final long getEventTime() { return mEventTime; } /** * Retrieve the time this event occurred, * in the {@link android.os.SystemClock#uptimeMillis} time base but with * nanosecond (instead of millisecond) precision. *

* The value is in nanosecond precision but it may not have nanosecond accuracy. *

* * @return Returns the time this event occurred, * in the {@link android.os.SystemClock#uptimeMillis} time base but with * nanosecond (instead of millisecond) precision. * * @hide */ @Override public final long getEventTimeNano() { return mEventTime * 1000000L; } /** * Renamed to {@link #getDeviceId}. * * @hide * @deprecated use {@link #getDeviceId()} instead. */ @Deprecated public final int getKeyboardDevice() { return mDeviceId; } /** * Gets the {@link KeyCharacterMap} associated with the keyboard device. * * @return The associated key character map. * @throws {@link KeyCharacterMap.UnavailableException} if the key character map * could not be loaded because it was malformed or the default key character map * is missing from the system. * * @see KeyCharacterMap#load */ public final KeyCharacterMap getKeyCharacterMap() { return KeyCharacterMap.load(mDeviceId); } /** * Gets the primary character for this key. * In other words, the label that is physically printed on it. * * @return The display label character, or 0 if none (eg. for non-printing keys). */ public char getDisplayLabel() { return getKeyCharacterMap().getDisplayLabel(mKeyCode); } /** * Gets the Unicode character generated by the specified key and meta * key state combination. *

* Returns the Unicode character that the specified key would produce * when the specified meta bits (see {@link MetaKeyKeyListener}) * were active. *

* Returns 0 if the key is not one that is used to type Unicode * characters. *

* If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the * key is a "dead key" that should be combined with another to * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} -- * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}. *

* * @return The associated character or combining accent, or 0 if none. */ public int getUnicodeChar() { return getUnicodeChar(mMetaState); } /** * Gets the Unicode character generated by the specified key and meta * key state combination. *

* Returns the Unicode character that the specified key would produce * when the specified meta bits (see {@link MetaKeyKeyListener}) * were active. *

* Returns 0 if the key is not one that is used to type Unicode * characters. *

* If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the * key is a "dead key" that should be combined with another to * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} -- * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}. *

* * @param metaState The meta key modifier state. * @return The associated character or combining accent, or 0 if none. */ public int getUnicodeChar(int metaState) { return getKeyCharacterMap().get(mKeyCode, metaState); } /** * Get the character conversion data for a given key code. * * @param results A {@link KeyCharacterMap.KeyData} instance that will be * filled with the results. * @return True if the key was mapped. If the key was not mapped, results is not modified. * * @deprecated instead use {@link #getDisplayLabel()}, * {@link #getNumber()} or {@link #getUnicodeChar(int)}. */ @Deprecated public boolean getKeyData(KeyData results) { return getKeyCharacterMap().getKeyData(mKeyCode, results); } /** * Gets the first character in the character array that can be generated * by the specified key code. *

* This is a convenience function that returns the same value as * {@link #getMatch(char[],int) getMatch(chars, 0)}. *

* * @param chars The array of matching characters to consider. * @return The matching associated character, or 0 if none. */ public char getMatch(char[] chars) { return getMatch(chars, 0); } /** * Gets the first character in the character array that can be generated * by the specified key code. If there are multiple choices, prefers * the one that would be generated with the specified meta key modifier state. * * @param chars The array of matching characters to consider. * @param metaState The preferred meta key modifier state. * @return The matching associated character, or 0 if none. */ public char getMatch(char[] chars, int metaState) { return getKeyCharacterMap().getMatch(mKeyCode, chars, metaState); } /** * Gets the number or symbol associated with the key. *

* The character value is returned, not the numeric value. * If the key is not a number, but is a symbol, the symbol is retuned. *

* This method is intended to to support dial pads and other numeric or * symbolic entry on keyboards where certain keys serve dual function * as alphabetic and symbolic keys. This method returns the number * or symbol associated with the key independent of whether the user * has pressed the required modifier. *

* For example, on one particular keyboard the keys on the top QWERTY row generate * numbers when ALT is pressed such that ALT-Q maps to '1'. So for that keyboard * when {@link #getNumber} is called with {@link KeyEvent#KEYCODE_Q} it returns '1' * so that the user can type numbers without pressing ALT when it makes sense. *

* * @return The associated numeric or symbolic character, or 0 if none. */ public char getNumber() { return getKeyCharacterMap().getNumber(mKeyCode); } /** * Returns true if this key produces a glyph. * * @return True if the key is a printing key. */ public boolean isPrintingKey() { return getKeyCharacterMap().isPrintingKey(mKeyCode); } /** * @deprecated Use {@link #dispatch(Callback, DispatcherState, Object)} instead. */ @Deprecated public final boolean dispatch(Callback receiver) { return dispatch(receiver, null, null); } /** * Deliver this key event to a {@link Callback} interface. If this is * an ACTION_MULTIPLE event and it is not handled, then an attempt will * be made to deliver a single normal event. * * @param receiver The Callback that will be given the event. * @param state State information retained across events. * @param target The target of the dispatch, for use in tracking. * * @return The return value from the Callback method that was called. */ public final boolean dispatch(Callback receiver, DispatcherState state, Object target) { switch (mAction) { case ACTION_DOWN: { mFlags &= ~FLAG_START_TRACKING; if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state + ": " + this); boolean res = receiver.onKeyDown(mKeyCode, this); if (state != null) { if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) { if (DEBUG) Log.v(TAG, " Start tracking!"); state.startTracking(this, target); } else if (isLongPress() && state.isTracking(this)) { try { if (receiver.onKeyLongPress(mKeyCode, this)) { if (DEBUG) Log.v(TAG, " Clear from long press!"); state.performedLongPress(this); res = true; } } catch (AbstractMethodError e) { } } } return res; } case ACTION_UP: if (DEBUG) Log.v(TAG, "Key up to " + target + " in " + state + ": " + this); if (state != null) { state.handleUpEvent(this); } return receiver.onKeyUp(mKeyCode, this); case ACTION_MULTIPLE: final int count = mRepeatCount; final int code = mKeyCode; if (receiver.onKeyMultiple(code, count, this)) { return true; } if (code != KeyEvent.KEYCODE_UNKNOWN) { mAction = ACTION_DOWN; mRepeatCount = 0; boolean handled = receiver.onKeyDown(code, this); if (handled) { mAction = ACTION_UP; receiver.onKeyUp(code, this); } mAction = ACTION_MULTIPLE; mRepeatCount = count; return handled; } return false; } return false; } /** * Use with {@link KeyEvent#dispatch(Callback, DispatcherState, Object)} * for more advanced key dispatching, such as long presses. */ public static class DispatcherState { int mDownKeyCode; Object mDownTarget; SparseIntArray mActiveLongPresses = new SparseIntArray(); /** * Reset back to initial state. */ public void reset() { if (DEBUG) Log.v(TAG, "Reset: " + this); mDownKeyCode = 0; mDownTarget = null; mActiveLongPresses.clear(); } /** * Stop any tracking associated with this target. */ public void reset(Object target) { if (mDownTarget == target) { if (DEBUG) Log.v(TAG, "Reset in " + target + ": " + this); mDownKeyCode = 0; mDownTarget = null; } } /** * Start tracking the key code associated with the given event. This * can only be called on a key down. It will allow you to see any * long press associated with the key, and will result in * {@link KeyEvent#isTracking} return true on the long press and up * events. * *

This is only needed if you are directly dispatching events, rather * than handling them in {@link Callback#onKeyDown}. */ public void startTracking(KeyEvent event, Object target) { if (event.getAction() != ACTION_DOWN) { throw new IllegalArgumentException( "Can only start tracking on a down event"); } if (DEBUG) Log.v(TAG, "Start trackingt in " + target + ": " + this); mDownKeyCode = event.getKeyCode(); mDownTarget = target; } /** * Return true if the key event is for a key code that is currently * being tracked by the dispatcher. */ public boolean isTracking(KeyEvent event) { return mDownKeyCode == event.getKeyCode(); } /** * Keep track of the given event's key code as having performed an * action with a long press, so no action should occur on the up. *

This is only needed if you are directly dispatching events, rather * than handling them in {@link Callback#onKeyLongPress}. */ public void performedLongPress(KeyEvent event) { mActiveLongPresses.put(event.getKeyCode(), 1); } /** * Handle key up event to stop tracking. This resets the dispatcher state, * and updates the key event state based on it. *

This is only needed if you are directly dispatching events, rather * than handling them in {@link Callback#onKeyUp}. */ public void handleUpEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (DEBUG) Log.v(TAG, "Handle key up " + event + ": " + this); int index = mActiveLongPresses.indexOfKey(keyCode); if (index >= 0) { if (DEBUG) Log.v(TAG, " Index: " + index); event.mFlags |= FLAG_CANCELED | FLAG_CANCELED_LONG_PRESS; mActiveLongPresses.removeAt(index); } if (mDownKeyCode == keyCode) { if (DEBUG) Log.v(TAG, " Tracking!"); event.mFlags |= FLAG_TRACKING; mDownKeyCode = 0; mDownTarget = null; } } } @Override public String toString() { StringBuilder msg = new StringBuilder(); msg.append("KeyEvent { action=").append(actionToString(mAction)); msg.append(", keyCode=").append(keyCodeToString(mKeyCode)); msg.append(", scanCode=").append(mScanCode); if (mCharacters != null) { msg.append(", characters=\"").append(mCharacters).append("\""); } msg.append(", metaState=").append(metaStateToString(mMetaState)); msg.append(", flags=0x").append(Integer.toHexString(mFlags)); msg.append(", repeatCount=").append(mRepeatCount); msg.append(", eventTime=").append(mEventTime); msg.append(", downTime=").append(mDownTime); msg.append(", deviceId=").append(mDeviceId); msg.append(", source=0x").append(Integer.toHexString(mSource)); msg.append(" }"); return msg.toString(); } /** * Returns a string that represents the symbolic name of the specified action * such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown. * * @param action The action. * @return The symbolic name of the specified action. * @hide */ public static String actionToString(int action) { switch (action) { case ACTION_DOWN: return "ACTION_DOWN"; case ACTION_UP: return "ACTION_UP"; case ACTION_MULTIPLE: return "ACTION_MULTIPLE"; default: return Integer.toString(action); } } /** * Returns a string that represents the symbolic name of the specified keycode * such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant * such as "1001" if unknown. * * @param keyCode The key code. * @return The symbolic name of the specified keycode. * * @see KeyCharacterMap#getDisplayLabel */ public static String keyCodeToString(int keyCode) { String symbolicName = KEYCODE_SYMBOLIC_NAMES.get(keyCode); return symbolicName != null ? symbolicName : Integer.toString(keyCode); } /** * Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent * numeric constant such as "1001". * * @param symbolicName The symbolic name of the keycode. * @return The keycode or {@link #KEYCODE_UNKNOWN} if not found. * @see #keycodeToString */ public static int keyCodeFromString(String symbolicName) { if (symbolicName == null) { throw new IllegalArgumentException("symbolicName must not be null"); } final int count = KEYCODE_SYMBOLIC_NAMES.size(); for (int i = 0; i < count; i++) { if (symbolicName.equals(KEYCODE_SYMBOLIC_NAMES.valueAt(i))) { return i; } } try { return Integer.parseInt(symbolicName, 10); } catch (NumberFormatException ex) { return KEYCODE_UNKNOWN; } } /** * Returns a string that represents the symbolic name of the specified combined meta * key modifier state flags such as "0", "META_SHIFT_ON", * "META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000" * if unknown. * * @param metaState The meta state. * @return The symbolic name of the specified combined meta state flags. * @hide */ public static String metaStateToString(int metaState) { if (metaState == 0) { return "0"; } StringBuilder result = null; int i = 0; while (metaState != 0) { final boolean isSet = (metaState & 1) != 0; metaState >>>= 1; // unsigned shift! if (isSet) { final String name = META_SYMBOLIC_NAMES[i]; if (result == null) { if (metaState == 0) { return name; } result = new StringBuilder(name); } else { result.append('|'); result.append(name); } } i += 1; } return result.toString(); } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public KeyEvent createFromParcel(Parcel in) { in.readInt(); // skip token, we already know this is a KeyEvent return KeyEvent.createFromParcelBody(in); } public KeyEvent[] newArray(int size) { return new KeyEvent[size]; } }; /** @hide */ public static KeyEvent createFromParcelBody(Parcel in) { return new KeyEvent(in); } private KeyEvent(Parcel in) { mDeviceId = in.readInt(); mSource = in.readInt(); mAction = in.readInt(); mKeyCode = in.readInt(); mRepeatCount = in.readInt(); mMetaState = in.readInt(); mScanCode = in.readInt(); mFlags = in.readInt(); mDownTime = in.readLong(); mEventTime = in.readLong(); } public void writeToParcel(Parcel out, int flags) { out.writeInt(PARCEL_TOKEN_KEY_EVENT); out.writeInt(mDeviceId); out.writeInt(mSource); out.writeInt(mAction); out.writeInt(mKeyCode); out.writeInt(mRepeatCount); out.writeInt(mMetaState); out.writeInt(mScanCode); out.writeInt(mFlags); out.writeLong(mDownTime); out.writeLong(mEventTime); } private native boolean native_isSystemKey(int keyCode); private native boolean native_hasDefaultAction(int keyCode); }

 public static final int KEYCODE_BACK = 4;

这种才是android上层应用所获取到的值.

 

待续 ...

 

 

你可能感兴趣的:(android KeyCode专题)