Android KeyCode 列表

一.KEYCODE列表

电话键


 
KEYCODE_CALL 拨号键 5
KEYCODE_ENDCALL 挂机键 6
KEYCODE_HOME 按键Home 3
KEYCODE_MENU 菜单 82
KEYCODE_BACK 返回键 4
KEYCODE_SEARCH 搜索 84
KEYCODE_CAMERA 拍照键 27
KEYCODE_FOCUS 拍照对焦键 80
KEYCODE_POWER 电源键 26
KEYCODE_NOTIFICATION 通知键 83
KEYCODE_MUTE 话筒静音键 91
KEYCODE_VOLUME_MUTE 扬声器静音键 164
KEYCODE_VOLUME_UP 音量增加键 24
KEYCODE_VOLUME_DOWN 音量减小键 25


控制键


 
KEYCODE_ENTER 回车键 66
KEYCODE_ESCAPE ESC键 111
KEYCODE_DPAD_CENTER 导航键 确定键 23
KEYCODE_DPAD_UP 导航键 向上 19
KEYCODE_DPAD_DOWN 导航键 向下 20
KEYCODE_DPAD_LEFT 导航键 向左 21
KEYCODE_DPAD_RIGHT 导航键 向右 22
KEYCODE_MOVE_HOME 光标移动到开始键 122
KEYCODE_MOVE_END 光标移动到末尾键 123
KEYCODE_PAGE_UP 向上翻页键 92
KEYCODE_PAGE_DOWN 向下翻页键 93
KEYCODE_DEL 退格键 67
KEYCODE_FORWARD_DEL 删除键 112
KEYCODE_INSERT 插入键 124
KEYCODE_TAB Tab键 61
KEYCODE_NUM_LOCK 小键盘锁 143
KEYCODE_CAPS_LOCK 大写锁定键 115
KEYCODE_BREAK Break/Pause键 121
KEYCODE_SCROLL_LOCK 滚动锁定键 116
KEYCODE_ZOOM_IN 放大键 168
KEYCODE_ZOOM_OUT 缩小键 169


组合键


 
KEYCODE_ALT_LEFT Alt+Left
KEYCODE_ALT_RIGHT Alt+Right
KEYCODE_CTRL_LEFT Control+Left
KEYCODE_CTRL_RIGHT Control+Right
KEYCODE_SHIFT_LEFT Shift+Left
KEYCODE_SHIFT_RIGHT Shift+Right


基本

 
KEYCODE_0 按键'0' 7
KEYCODE_1 按键'1' 8
KEYCODE_2 按键'2' 9
KEYCODE_3 按键'3' 10
KEYCODE_4 按键'4' 11
KEYCODE_5 按键'5' 12
KEYCODE_6 按键'6' 13
KEYCODE_7 按键'7' 14
KEYCODE_8 按键'8' 15
KEYCODE_9 按键'9' 16
KEYCODE_A 按键'A' 29
KEYCODE_B 按键'B' 30
KEYCODE_C 按键'C' 31
KEYCODE_D 按键'D' 32
KEYCODE_E 按键'E' 33
KEYCODE_F 按键'F' 34
KEYCODE_G 按键'G' 35
KEYCODE_H 按键'H' 36
KEYCODE_I 按键'I' 37
KEYCODE_J 按键'J' 38
KEYCODE_K 按键'K' 39
KEYCODE_L 按键'L' 40
KEYCODE_M 按键'M' 41
KEYCODE_N 按键'N' 42
KEYCODE_O 按键'O' 43
KEYCODE_P 按键'P' 44
KEYCODE_Q 按键'Q' 45
KEYCODE_R 按键'R' 46
KEYCODE_S 按键'S' 47
KEYCODE_T 按键'T' 48
KEYCODE_U 按键'U' 49
KEYCODE_V 按键'V' 50
KEYCODE_W 按键'W' 51
KEYCODE_X 按键'X' 52
KEYCODE_Y 按键'Y' 53
KEYCODE_Z 按键'Z' 54


符号


 
KEYCODE_PLUS 按键'+'
KEYCODE_MINUS 按键'-'
KEYCODE_STAR 按键'*'
KEYCODE_SLASH 按键'/'
KEYCODE_EQUALS 按键'='
KEYCODE_AT 按键'@'
KEYCODE_POUND 按键'#'
KEYCODE_APOSTROPHE 按键''' (单引号)
KEYCODE_BACKSLASH 按键'\'
KEYCODE_COMMA 按键','
KEYCODE_PERIOD 按键'.'
KEYCODE_LEFT_BRACKET 按键'['
KEYCODE_RIGHT_BRACKET 按键']'
KEYCODE_SEMICOLON 按键';'
KEYCODE_GRAVE 按键'`'
KEYCODE_SPACE 空格键


小键盘


 
KEYCODE_NUMPAD_0 小键盘按键'0'
KEYCODE_NUMPAD_1 小键盘按键'1'
KEYCODE_NUMPAD_2 小键盘按键'2'
KEYCODE_NUMPAD_3 小键盘按键'3'
KEYCODE_NUMPAD_4 小键盘按键'4'
KEYCODE_NUMPAD_5 小键盘按键'5'
KEYCODE_NUMPAD_6 小键盘按键'6'
KEYCODE_NUMPAD_7 小键盘按键'7'
KEYCODE_NUMPAD_8 小键盘按键'8'
KEYCODE_NUMPAD_9 小键盘按键'9'
KEYCODE_NUMPAD_ADD 小键盘按键'+'
KEYCODE_NUMPAD_SUBTRACT 小键盘按键'-'
KEYCODE_NUMPAD_MULTIPLY 小键盘按键'*'
KEYCODE_NUMPAD_DIVIDE 小键盘按键'/'
KEYCODE_NUMPAD_EQUALS 小键盘按键'='
KEYCODE_NUMPAD_COMMA 小键盘按键','
KEYCODE_NUMPAD_DOT 小键盘按键'.'
KEYCODE_NUMPAD_LEFT_PAREN 小键盘按键'('
KEYCODE_NUMPAD_RIGHT_PAREN 小键盘按键')'
KEYCODE_NUMPAD_ENTER 小键盘按键回车


功能键


 
KEYCODE_F1 按键F1
KEYCODE_F2 按键F2
KEYCODE_F3 按键F3
KEYCODE_F4 按键F4
KEYCODE_F5 按键F5
KEYCODE_F6 按键F6
KEYCODE_F7 按键F7
KEYCODE_F8 按键F8
KEYCODE_F9 按键F9
KEYCODE_F10 按键F10
KEYCODE_F11 按键F11
KEYCODE_F12 按键F12


多媒体键


 
KEYCODE_MEDIA_PLAY 多媒体键 播放
KEYCODE_MEDIA_STOP 多媒体键 停止
KEYCODE_MEDIA_PAUSE 多媒体键 暂停
KEYCODE_MEDIA_PLAY_PAUSE 多媒体键 播放/暂停
KEYCODE_MEDIA_FAST_FORWARD 多媒体键 快进
KEYCODE_MEDIA_REWIND 多媒体键 快退
KEYCODE_MEDIA_NEXT 多媒体键 下一首
KEYCODE_MEDIA_PREVIOUS 多媒体键 上一首
KEYCODE_MEDIA_CLOSE 多媒体键 关闭
KEYCODE_MEDIA_EJECT 多媒体键 弹出
KEYCODE_MEDIA_RECORD 多媒体键 录音


手柄按键


 
KEYCODE_BUTTON_1 通用游戏手柄按钮#1
KEYCODE_BUTTON_2 通用游戏手柄按钮 #2
KEYCODE_BUTTON_3 通用游戏手柄按钮 #3
KEYCODE_BUTTON_4 通用游戏手柄按钮 #4
KEYCODE_BUTTON_5 通用游戏手柄按钮 #5
KEYCODE_BUTTON_6 通用游戏手柄按钮 #6
KEYCODE_BUTTON_7 通用游戏手柄按钮 #7
KEYCODE_BUTTON_8 通用游戏手柄按钮 #8
KEYCODE_BUTTON_9 通用游戏手柄按钮 #9
KEYCODE_BUTTON_10 通用游戏手柄按钮 #10
KEYCODE_BUTTON_11 通用游戏手柄按钮 #11
KEYCODE_BUTTON_12 通用游戏手柄按钮 #12
KEYCODE_BUTTON_13 通用游戏手柄按钮 #13
KEYCODE_BUTTON_14 通用游戏手柄按钮 #14
KEYCODE_BUTTON_15 通用游戏手柄按钮 #15
KEYCODE_BUTTON_16 通用游戏手柄按钮 #16
KEYCODE_BUTTON_A 游戏手柄按钮 A
KEYCODE_BUTTON_B 游戏手柄按钮 B
KEYCODE_BUTTON_C 游戏手柄按钮 C
KEYCODE_BUTTON_X 游戏手柄按钮 X
KEYCODE_BUTTON_Y 游戏手柄按钮 Y
KEYCODE_BUTTON_Z 游戏手柄按钮 Z
KEYCODE_BUTTON_L1 游戏手柄按钮 L1
KEYCODE_BUTTON_L2 游戏手柄按钮 L2
KEYCODE_BUTTON_R1 游戏手柄按钮 R1
KEYCODE_BUTTON_R2 游戏手柄按钮 R2
KEYCODE_BUTTON_MODE 游戏手柄按钮 Mode
KEYCODE_BUTTON_SELECT 游戏手柄按钮 Select
KEYCODE_BUTTON_START 游戏手柄按钮 Start
KEYCODE_BUTTON_THUMBL Left Thumb Button
KEYCODE_BUTTON_THUMBR Right Thumb Button


待查

 

 

KEYCODE_NUM

按键Number modifier

KEYCODE_INFO

按键Info

KEYCODE_APP_SWITCH

按键App switch

KEYCODE_BOOKMARK

按键Bookmark

KEYCODE_AVR_INPUT

按键A/V Receiver input

KEYCODE_AVR_POWER

按键A/V Receiver power

KEYCODE_CAPTIONS

按键Toggle captions

KEYCODE_CHANNEL_DOWN

按键Channel down

KEYCODE_CHANNEL_UP

按键Channel up

KEYCODE_CLEAR

按键Clear

KEYCODE_DVR

按键DVR

KEYCODE_ENVELOPE

按键Envelope special function

KEYCODE_EXPLORER

按键Explorer special function

KEYCODE_FORWARD

按键Forward

KEYCODE_FORWARD_DEL

按键Forward Delete

KEYCODE_FUNCTION

按键Function modifier

KEYCODE_GUIDE

按键Guide

KEYCODE_HEADSETHOOK

按键Headset Hook

KEYCODE_META_LEFT

按键Left Meta modifier

KEYCODE_META_RIGHT

按键Right Meta modifier

KEYCODE_PICTSYMBOLS

按键Picture Symbols modifier

KEYCODE_PROG_BLUE

按键Blue “programmable”

KEYCODE_PROG_GREEN

按键Green “programmable”

KEYCODE_PROG_RED

按键Red “programmable”

KEYCODE_PROG_YELLOW

按键Yellow “programmable”

KEYCODE_SETTINGS

按键Settings

KEYCODE_SOFT_LEFT

按键Soft Left

KEYCODE_SOFT_RIGHT

按键Soft Right

KEYCODE_STB_INPUT

按键Set-top-box input

KEYCODE_STB_POWER

按键Set-top-box power

KEYCODE_SWITCH_CHARSET

按键Switch Charset modifier

KEYCODE_SYM

按键Symbol modifier

KEYCODE_SYSRQ

按键System Request / Print Screen

KEYCODE_TV

按键TV

KEYCODE_TV_INPUT

按键TV input

KEYCODE_TV_POWER

按键TV power

KEYCODE_WINDOW

按键Window

KEYCODE_UNKNOWN

未知按键

二.底层代码实现

frameworks/base/data/keyboards/Generic.kl

   1 key 1     ESCAPE
   2 key 2     1
   3 key 3     2
   4 key 4     3
   5 key 5     4
   6 key 6     5
   7 key 7     6
   8 key 8     7
   9 key 9     8
  10 key 10    9
  11 key 11    0
  12 key 12    MINUS
  13 key 13    EQUALS
  14 key 14    DEL
  15 key 15    TAB
  16 key 16    Q
  17 key 17    W
  18 key 18    E
  19 key 19    R
  20 key 20    T
  21 key 21    Y
  22 key 22    U
  23 key 23    I
  24 key 24    O
  25 key 25    P
  26 key 26    LEFT_BRACKET
  27 key 27    RIGHT_BRACKET
  28 key 28    ENTER
  29 key 29    CTRL_LEFT
  30 key 30    A
  31 key 31    S
  32 key 32    D
  33 key 33    F
  34 key 34    G
  35 key 35    H
  36 key 36    J
  37 key 37    K
  38 key 38    L
  39 key 39    SEMICOLON
  40 key 40    APOSTROPHE
  41 key 41    GRAVE
  42 key 42    SHIFT_LEFT
  43 key 43    BACKSLASH
  44 key 44    Z
  45 key 45    X
  46 key 46    C
  47 key 47    V
  48 key 48    B
  49 key 49    N
  50 key 50    M
  51 key 51    COMMA
  52 key 52    PERIOD
  53 key 53    SLASH
  54 key 54    SHIFT_RIGHT
  55 key 55    NUMPAD_MULTIPLY
  56 key 56    ALT_LEFT
  57 key 57    SPACE
  58 key 58    CAPS_LOCK
  59 key 59    F1
  60 key 60    F2
  61 key 61    F3
  62 key 62    F4
  63 key 63    F5
  64 key 64    F6
  65 key 65    F7
  66 key 66    F8
  67 key 67    F9
  68 key 68    F10
  69 key 69    NUM_LOCK
  70 key 70    SCROLL_LOCK
  71 key 71    NUMPAD_7
  72 key 72    NUMPAD_8
  73 key 73    NUMPAD_9
  74 key 74    NUMPAD_SUBTRACT
  75 key 75    NUMPAD_4
  76 key 76    NUMPAD_5
  77 key 77    NUMPAD_6
  78 key 78    NUMPAD_ADD
  79 key 79    NUMPAD_1
  80 key 80    NUMPAD_2
  81 key 81    NUMPAD_3
  82 key 82    NUMPAD_0
  83 key 83    NUMPAD_DOT
  84 # key 84 (undefined)
  85 key 85    ZENKAKU_HANKAKU
  86 key 86    BACKSLASH
  87 key 87    F11
  88 key 88    F12
  89 key 89    RO
  90 # key 90 "KEY_KATAKANA"
  91 # key 91 "KEY_HIRAGANA"
  92 key 92    HENKAN
  93 key 93    KATAKANA_HIRAGANA
  94 key 94    MUHENKAN
  95 key 95    NUMPAD_COMMA
  96 key 96    NUMPAD_ENTER
  97 key 97    CTRL_RIGHT
  98 key 98    NUMPAD_DIVIDE
  99 key 99    SYSRQ
 100 key 100   ALT_RIGHT
 101 # key 101 "KEY_LINEFEED"
 102 key 102   MOVE_HOME
 103 key 103   DPAD_UP
 104 key 104   PAGE_UP
 105 key 105   DPAD_LEFT
 106 key 106   DPAD_RIGHT
 107 key 107   MOVE_END
 108 key 108   DPAD_DOWN
 109 key 109   PAGE_DOWN
 110 key 110   INSERT
 111 key 111   FORWARD_DEL
 112 # key 112 "KEY_MACRO"
 113 key 113   VOLUME_MUTE
 114 key 114   VOLUME_DOWN
 115 key 115   VOLUME_UP
 116 key 116   POWER             WAKE
 117 key 117   NUMPAD_EQUALS
 118 # key 118 "KEY_KPPLUSMINUS"
 119 key 119   BREAK
 120 # key 120 (undefined)
 121 key 121   NUMPAD_COMMA
 122 key 122   KANA
 123 key 123   EISU
 124 key 124   YEN
 125 key 125   META_LEFT
 126 key 126   META_RIGHT
 127 key 127   MENU              WAKE_DROPPED
 128 key 128   MEDIA_STOP
 129 # key 129 "KEY_AGAIN"
 130 # key 130 "KEY_PROPS"
 131 # key 131 "KEY_UNDO"
 132 # key 132 "KEY_FRONT"
 133 # key 133 "KEY_COPY"
 134 # key 134 "KEY_OPEN"
 135 # key 135 "KEY_PASTE"
 136 # key 136 "KEY_FIND"
 137 # key 137 "KEY_CUT"
 138 # key 138 "KEY_HELP"
 139 key 139   MENU              WAKE_DROPPED
 140 key 140   CALCULATOR
 141 # key 141 "KEY_SETUP"
 142 key 142   POWER             WAKE
 143 key 143   POWER             WAKE
 144 # key 144 "KEY_FILE"
 145 # key 145 "KEY_SENDFILE"
 146 # key 146 "KEY_DELETEFILE"
 147 # key 147 "KEY_XFER"
 148 # key 148 "KEY_PROG1"
 149 # key 149 "KEY_PROG2"
 150 key 150   EXPLORER
 151 # key 151 "KEY_MSDOS"
 152 key 152   POWER             WAKE
 153 # key 153 "KEY_DIRECTION"
 154 # key 154 "KEY_CYCLEWINDOWS"
 155 key 155   ENVELOPE
 156 key 156   BOOKMARK
 157 # key 157 "KEY_COMPUTER"
 158 key 158   BACK              WAKE_DROPPED
 159 key 159   FORWARD
 160 key 160   MEDIA_CLOSE
 161 key 161   MEDIA_EJECT
 162 key 162   MEDIA_EJECT
 163 key 163   MEDIA_NEXT
 164 key 164   MEDIA_PLAY_PAUSE
 165 key 165   MEDIA_PREVIOUS
 166 key 166   MEDIA_STOP
 167 key 167   MEDIA_RECORD
 168 key 168   MEDIA_REWIND
 169 key 169   CALL
 170 # key 170 "KEY_ISO"
 171 key 171   MUSIC
 172 key 172   HOME
 173 # key 173 "KEY_REFRESH"
 174 # key 174 "KEY_EXIT"
 175 # key 175 "KEY_MOVE"
 176 # key 176 "KEY_EDIT"
 177 key 177   PAGE_UP
 178 key 178   PAGE_DOWN
 179 key 179   NUMPAD_LEFT_PAREN
 180 key 180   NUMPAD_RIGHT_PAREN
 181 # key 181 "KEY_NEW"
 182 # key 182 "KEY_REDO"
 183 # key 183   F13
 184 # key 184   F14
 185 # key 185   F15
 186 # key 186   F16
 187 # key 187   F17
 188 # key 188   F18
 189 # key 189   F19
 190 # key 190   F20
 191 # key 191   F21
 192 # key 192   F22
 193 # key 193   F23
 194 # key 194   F24
 195 # key 195 (undefined)
 196 # key 196 (undefined)
 197 # key 197 (undefined)
 198 # key 198 (undefined)
 199 # key 199 (undefined)
 200 key 200   MEDIA_PLAY
 201 key 201   MEDIA_PAUSE
 202 # key 202 "KEY_PROG3"
 203 # key 203 "KEY_PROG4"
 204 # key 204 (undefined)
 205 # key 205 "KEY_SUSPEND"
 206 # key 206 "KEY_CLOSE"
 207 key 207   MEDIA_PLAY
 208 key 208   MEDIA_FAST_FORWARD
 209 # key 209 "KEY_BASSBOOST"
 210 # key 210 "KEY_PRINT"
 211 # key 211 "KEY_HP"
 212 key 212   CAMERA
 213 key 213   MUSIC
 214 # key 214 "KEY_QUESTION"
 215 key 215   ENVELOPE
 216 # key 216 "KEY_CHAT"
 217 key 217   SEARCH
 218 # key 218 "KEY_CONNECT"
 219 # key 219 "KEY_FINANCE"
 220 # key 220 "KEY_SPORT"
 221 # key 221 "KEY_SHOP"
 222 # key 222 "KEY_ALTERASE"
 223 # key 223 "KEY_CANCEL"
 224 # key 224 "KEY_BRIGHTNESSDOWN"
 225 # key 225 "KEY_BRIGHTNESSUP"
 226 key 226   HEADSETHOOK
 227 
 228 key 256   BUTTON_1
 229 key 257   BUTTON_2
 230 key 258   BUTTON_3
 231 key 259   BUTTON_4
 232 key 260   BUTTON_5
 233 key 261   BUTTON_6
 234 key 262   BUTTON_7
 235 key 263   BUTTON_8
 236 key 264   BUTTON_9
 237 key 265   BUTTON_10
 238 key 266   BUTTON_11
 239 key 267   BUTTON_12
 240 key 268   BUTTON_13
 241 key 269   BUTTON_14
 242 key 270   BUTTON_15
 243 key 271   BUTTON_16
 244 
 245 key 288   BUTTON_1
 246 key 289   BUTTON_2
 247 key 290   BUTTON_3
 248 key 291   BUTTON_4
 249 key 292   BUTTON_5
 250 key 293   BUTTON_6
 251 key 294   BUTTON_7
 252 key 295   BUTTON_8
 253 key 296   BUTTON_9
 254 key 297   BUTTON_10
 255 key 298   BUTTON_11
 256 key 299   BUTTON_12
 257 key 300   BUTTON_13
 258 key 301   BUTTON_14
 259 key 302   BUTTON_15
 260 key 303   BUTTON_16
 261 
 262 
 263 key 304   BUTTON_A
 264 key 305   BUTTON_B
 265 key 306   BUTTON_C
 266 key 307   BUTTON_X
 267 key 308   BUTTON_Y
 268 key 309   BUTTON_Z
 269 key 310   BUTTON_L1
 270 key 311   BUTTON_R1
 271 key 312   BUTTON_L2
 272 key 313   BUTTON_R2
 273 key 314   BUTTON_SELECT
 274 key 315   BUTTON_START
 275 key 316   BUTTON_MODE
 276 key 317   BUTTON_THUMBL
 277 key 318   BUTTON_THUMBR
 278 
 279 
 280 # key 352 "KEY_OK"
 281 key 353   DPAD_CENTER
 282 # key 354 "KEY_GOTO"
 283 # key 355 "KEY_CLEAR"
 284 # key 356 "KEY_POWER2"
 285 # key 357 "KEY_OPTION"
 286 # key 358 "KEY_INFO"
 287 # key 359 "KEY_TIME"
 288 # key 360 "KEY_VENDOR"
 289 # key 361 "KEY_ARCHIVE"
 290 key 362   GUIDE
 291 # key 363 "KEY_CHANNEL"
 292 # key 364 "KEY_FAVORITES"
 293 # key 365 "KEY_EPG"
 294 key 366   DVR
 295 # key 367 "KEY_MHP"
 296 # key 368 "KEY_LANGUAGE"
 297 # key 369 "KEY_TITLE"
 298 # key 370 "KEY_SUBTITLE"
 299 # key 371 "KEY_ANGLE"
 300 # key 372 "KEY_ZOOM"
 301 # key 373 "KEY_MODE"
 302 # key 374 "KEY_KEYBOARD"
 303 # key 375 "KEY_SCREEN"
 304 # key 376 "KEY_PC"
 305 key 377   TV
 306 # key 378 "KEY_TV2"
 307 # key 379 "KEY_VCR"
 308 # key 380 "KEY_VCR2"
 309 # key 381 "KEY_SAT"
 310 # key 382 "KEY_SAT2"
 311 # key 383 "KEY_CD"
 312 # key 384 "KEY_TAPE"
 313 # key 385 "KEY_RADIO"
 314 # key 386 "KEY_TUNER"
 315 # key 387 "KEY_PLAYER"
 316 # key 388 "KEY_TEXT"
 317 # key 389 "KEY_DVD"
 318 # key 390 "KEY_AUX"
 319 # key 391 "KEY_MP3"
 320 # key 392 "KEY_AUDIO"
 321 # key 393 "KEY_VIDEO"
 322 # key 394 "KEY_DIRECTORY"
 323 # key 395 "KEY_LIST"
 324 # key 396 "KEY_MEMO"
 325 key 397   CALENDAR
 326 # key 398 "KEY_RED"
 327 # key 399 "KEY_GREEN"
 328 # key 400 "KEY_YELLOW"
 329 # key 401 "KEY_BLUE"
 330 key 402   CHANNEL_UP
 331 key 403   CHANNEL_DOWN
 332 # key 404 "KEY_FIRST"
 333 # key 405 "KEY_LAST"
 334 # key 406 "KEY_AB"
 335 # key 407 "KEY_NEXT"
 336 # key 408 "KEY_RESTART"
 337 # key 409 "KEY_SLOW"
 338 # key 410 "KEY_SHUFFLE"
 339 # key 411 "KEY_BREAK"
 340 # key 412 "KEY_PREVIOUS"
 341 # key 413 "KEY_DIGITS"
 342 # key 414 "KEY_TEEN"
 343 # key 415 "KEY_TWEN"
 344 
 345 key 429   CONTACTS
 346 
 347 # key 448 "KEY_DEL_EOL"
 348 # key 449 "KEY_DEL_EOS"
 349 # key 450 "KEY_INS_LINE"
 350 # key 451 "KEY_DEL_LINE"
 351 
 352 
 353 key 464   FUNCTION
 354 key 465   ESCAPE            FUNCTION
 355 key 466   F1                FUNCTION
 356 key 467   F2                FUNCTION
 357 key 468   F3                FUNCTION
 358 key 469   F4                FUNCTION
 359 key 470   F5                FUNCTION
 360 key 471   F6                FUNCTION
 361 key 472   F7                FUNCTION
 362 key 473   F8                FUNCTION
 363 key 474   F9                FUNCTION
 364 key 475   F10               FUNCTION
 365 key 476   F11               FUNCTION
 366 key 477   F12               FUNCTION
 367 key 478   1                 FUNCTION
 368 key 479   2                 FUNCTION
 369 key 480   D                 FUNCTION
 370 key 481   E                 FUNCTION
 371 key 482   F                 FUNCTION
 372 key 483   S                 FUNCTION
 373 key 484   B                 FUNCTION
 374 
 375 
 376 # key 497 KEY_BRL_DOT1
 377 # key 498 KEY_BRL_DOT2
 378 # key 499 KEY_BRL_DOT3
 379 # key 500 KEY_BRL_DOT4
 380 # key 501 KEY_BRL_DOT5
 381 # key 502 KEY_BRL_DOT6
 382 # key 503 KEY_BRL_DOT7
 383 # key 504 KEY_BRL_DOT8
 384 
 385 
 386 # Joystick and game controller axes.
 387 # Axes that are not mapped will be assigned generic axis numbers by the input subsystem.
 388 axis 0x00 X
 389 axis 0x01 Y
 390 axis 0x02 Z
 391 axis 0x03 RX
 392 axis 0x04 RY
 393 axis 0x05 RZ
 394 axis 0x06 THROTTLE
 395 axis 0x07 RUDDER
 396 axis 0x08 WHEEL
 397 axis 0x09 GAS
 398 axis 0x0a BRAKE
 399 axis 0x10 HAT_X
 400 axis 0x11 HAT_Y
 401 
 402  key  158   BACK WAKE_DROPPED
 403 
 404 类型  CODE  NAME
 405 
 406 有些没有用到的用'#'注释
 407 
 408  
 409 
 410 kernel/include/linux/input.h
 411 
 412 #ifndef _INPUT_H
 413 #define _INPUT_H
 414 
 415 /*
 416  * Copyright (c) 1999-2002 Vojtech Pavlik
 417  *
 418  * This program is free software; you can redistribute it and/or modify it
 419  * under the terms of the GNU General Public License version 2 as published by
 420  * the Free Software Foundation.
 421  */
 422 
 423 #ifdef __KERNEL__
 424 #include <linux/time.h>
 425 #include <linux/list.h>
 426 #else
 427 #include <sys/time.h>
 428 #include <sys/ioctl.h>
 429 #include <sys/types.h>
 430 #include <linux/types.h>
 431 #endif
 432 
 433 /*
 434  * The event structure itself
 435  */
 436 
 437 struct input_event {
 438     struct timeval time;
 439     __u16 type;
 440     __u16 code;
 441     __s32 value;
 442 };
 443 
 444 /*
 445  * Protocol version.
 446  */
 447 
 448 #define EV_VERSION        0x010001
 449 
 450 /*
 451  * IOCTLs (0x00 - 0x7f)
 452  */
 453 
 454 struct input_id {
 455     __u16 bustype;
 456     __u16 vendor;
 457     __u16 product;
 458     __u16 version;
 459 };
 460 
 461 /**
 462  * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
 463  * @value: latest reported value for the axis.
 464  * @minimum: specifies minimum value for the axis.
 465  * @maximum: specifies maximum value for the axis.
 466  * @fuzz: specifies fuzz value that is used to filter noise from
 467  *    the event stream.
 468  * @flat: values that are within this value will be discarded by
 469  *    joydev interface and reported as 0 instead.
 470  * @resolution: specifies resolution for the values reported for
 471  *    the axis.
 472  *
 473  * Note that input core does not clamp reported values to the
 474  * [minimum, maximum] limits, such task is left to userspace.
 475  *
 476  * Resolution for main axes (ABS_X, ABS_Y, ABS_Z) is reported in
 477  * units per millimeter (units/mm), resolution for rotational axes
 478  * (ABS_RX, ABS_RY, ABS_RZ) is reported in units per radian.
 479  */
 480 struct input_absinfo {
 481     __s32 value;
 482     __s32 minimum;
 483     __s32 maximum;
 484     __s32 fuzz;
 485     __s32 flat;
 486     __s32 resolution;
 487 };
 488 
 489 /**
 490  * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
 491  * @scancode: scancode represented in machine-endian form.
 492  * @len: length of the scancode that resides in @scancode buffer.
 493  * @index: index in the keymap, may be used instead of scancode
 494  * @flags: allows to specify how kernel should handle the request. For
 495  *    example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
 496  *    should perform lookup in keymap by @index instead of @scancode
 497  * @keycode: key code assigned to this scancode
 498  *
 499  * The structure is used to retrieve and modify keymap data. Users have
 500  * option of performing lookup either by @scancode itself or by @index
 501  * in keymap entry. EVIOCGKEYCODE will also return scancode or index
 502  * (depending on which element was used to perform lookup).
 503  */
 504 struct input_keymap_entry {
 505 #define INPUT_KEYMAP_BY_INDEX    (1 << 0)
 506     __u8  flags;
 507     __u8  len;
 508     __u16 index;
 509     __u32 keycode;
 510     __u8  scancode[32];
 511 };
 512 
 513 #define EVIOCGVERSION        _IOR('E', 0x01, int)            /* get driver version */
 514 #define EVIOCGID        _IOR('E', 0x02, struct input_id)    /* get device ID */
 515 #define EVIOCGREP        _IOR('E', 0x03, unsigned int[2])    /* get repeat settings */
 516 #define EVIOCSREP        _IOW('E', 0x03, unsigned int[2])    /* set repeat settings */
 517 
 518 #define EVIOCGKEYCODE        _IOR('E', 0x04, unsigned int[2])        /* get keycode */
 519 #define EVIOCGKEYCODE_V2    _IOR('E', 0x04, struct input_keymap_entry)
 520 #define EVIOCSKEYCODE        _IOW('E', 0x04, unsigned int[2])        /* set keycode */
 521 #define EVIOCSKEYCODE_V2    _IOW('E', 0x04, struct input_keymap_entry)
 522 
 523 #define EVIOCGNAME(len)        _IOC(_IOC_READ, 'E', 0x06, len)        /* get device name */
 524 #define EVIOCGPHYS(len)        _IOC(_IOC_READ, 'E', 0x07, len)        /* get physical location */
 525 #define EVIOCGUNIQ(len)        _IOC(_IOC_READ, 'E', 0x08, len)        /* get unique identifier */
 526 #define EVIOCGPROP(len)        _IOC(_IOC_READ, 'E', 0x09, len)        /* get device properties */
 527 
 528 #define EVIOCGKEY(len)        _IOC(_IOC_READ, 'E', 0x18, len)        /* get global key state */
 529 #define EVIOCGLED(len)        _IOC(_IOC_READ, 'E', 0x19, len)        /* get all LEDs */
 530 #define EVIOCGSND(len)        _IOC(_IOC_READ, 'E', 0x1a, len)        /* get all sounds status */
 531 #define EVIOCGSW(len)        _IOC(_IOC_READ, 'E', 0x1b, len)        /* get all switch states */
 532 
 533 #define EVIOCGBIT(ev,len)    _IOC(_IOC_READ, 'E', 0x20 + ev, len)    /* get event bits */
 534 #define EVIOCGABS(abs)        _IOR('E', 0x40 + abs, struct input_absinfo)    /* get abs value/limits */
 535 #define EVIOCSABS(abs)        _IOW('E', 0xc0 + abs, struct input_absinfo)    /* set abs value/limits */
 536 
 537 #define EVIOCSFF        _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect))    /* send a force effect to a force feedback device */
 538 #define EVIOCRMFF        _IOW('E', 0x81, int)            /* Erase a force effect */
 539 #define EVIOCGEFFECTS        _IOR('E', 0x84, int)            /* Report number of effects playable at the same time */
 540 
 541 #define EVIOCGRAB        _IOW('E', 0x90, int)            /* Grab/Release device */
 542 
 543 #define EVIOCGSUSPENDBLOCK    _IOR('E', 0x91, int)            /* get suspend block enable */
 544 #define EVIOCSSUSPENDBLOCK    _IOW('E', 0x91, int)            /* set suspend block enable */
 545 
 546 /*
 547  * Device properties and quirks
 548  */
 549 
 550 #define INPUT_PROP_POINTER        0x00    /* needs a pointer */
 551 #define INPUT_PROP_DIRECT        0x01    /* direct input devices */
 552 #define INPUT_PROP_BUTTONPAD        0x02    /* has button(s) under pad */
 553 #define INPUT_PROP_SEMI_MT        0x03    /* touch rectangle only */
 554 
 555 #define INPUT_PROP_MAX            0x1f
 556 #define INPUT_PROP_CNT            (INPUT_PROP_MAX + 1)
 557 
 558 /*
 559  * Event types
 560  */
 561 
 562 #define EV_SYN            0x00
 563 #define EV_KEY            0x01
 564 #define EV_REL            0x02
 565 #define EV_ABS            0x03
 566 #define EV_MSC            0x04
 567 #define EV_SW            0x05
 568 #define EV_LED            0x11
 569 #define EV_SND            0x12
 570 #define EV_REP            0x14
 571 #define EV_FF            0x15
 572 #define EV_PWR            0x16
 573 #define EV_FF_STATUS        0x17
 574 #define EV_MAX            0x1f
 575 #define EV_CNT            (EV_MAX+1)
 576 
 577 /*
 578  * Synchronization events.
 579  */
 580 
 581 #define SYN_REPORT        0
 582 #define SYN_CONFIG        1
 583 #define SYN_MT_REPORT        2
 584 #define SYN_DROPPED        3
 585 
 586 /*
 587  * Keys and buttons
 588  *
 589  * Most of the keys/buttons are modeled after USB HUT 1.12
 590  * (see http://www.usb.org/developers/hidpage).
 591  * Abbreviations in the comments:
 592  * AC - Application Control
 593  * AL - Application Launch Button
 594  * SC - System Control
 595  */
 596 
 597 #define KEY_RESERVED        0
 598 #define KEY_ESC            1
 599 #define KEY_1            2
 600 #define KEY_2            3
 601 #define KEY_3            4
 602 #define KEY_4            5
 603 #define KEY_5            6
 604 #define KEY_6            7
 605 #define KEY_7            8
 606 #define KEY_8            9
 607 #define KEY_9            10
 608 #define KEY_0            11
 609 #define KEY_MINUS        12
 610 #define KEY_EQUAL        13
 611 #define KEY_BACKSPACE        14
 612 #define KEY_TAB            15
 613 #define KEY_Q            16
 614 #define KEY_W            17
 615 #define KEY_E            18
 616 #define KEY_R            19
 617 #define KEY_T            20
 618 #define KEY_Y            21
 619 #define KEY_U            22
 620 #define KEY_I            23
 621 #define KEY_O            24
 622 #define KEY_P            25
 623 #define KEY_LEFTBRACE        26
 624 #define KEY_RIGHTBRACE        27
 625 #define KEY_ENTER        28
 626 #define KEY_LEFTCTRL        29
 627 #define KEY_A            30
 628 #define KEY_S            31
 629 #define KEY_D            32
 630 #define KEY_F            33
 631 #define KEY_G            34
 632 #define KEY_H            35
 633 #define KEY_J            36
 634 #define KEY_K            37
 635 #define KEY_L            38
 636 #define KEY_SEMICOLON        39
 637 #define KEY_APOSTROPHE        40
 638 #define KEY_GRAVE        41
 639 #define KEY_LEFTSHIFT        42
 640 #define KEY_BACKSLASH        43
 641 #define KEY_Z            44
 642 #define KEY_X            45
 643 #define KEY_C            46
 644 #define KEY_V            47
 645 #define KEY_B            48
 646 #define KEY_N            49
 647 #define KEY_M            50
 648 #define KEY_COMMA        51
 649 #define KEY_DOT            52
 650 #define KEY_SLASH        53
 651 #define KEY_RIGHTSHIFT        54
 652 #define KEY_KPASTERISK        55
 653 #define KEY_LEFTALT        56
 654 #define KEY_SPACE        57
 655 #define KEY_CAPSLOCK        58
 656 #define KEY_F1            59
 657 #define KEY_F2            60
 658 #define KEY_F3            61
 659 #define KEY_F4            62
 660 #define KEY_F5            63
 661 #define KEY_F6            64
 662 #define KEY_F7            65
 663 #define KEY_F8            66
 664 #define KEY_F9            67
 665 #define KEY_F10            68
 666 #define KEY_NUMLOCK        69
 667 #define KEY_SCROLLLOCK        70
 668 #define KEY_KP7            71
 669 #define KEY_KP8            72
 670 #define KEY_KP9            73
 671 #define KEY_KPMINUS        74
 672 #define KEY_KP4            75
 673 #define KEY_KP5            76
 674 #define KEY_KP6            77
 675 #define KEY_KPPLUS        78
 676 #define KEY_KP1            79
 677 #define KEY_KP2            80
 678 #define KEY_KP3            81
 679 #define KEY_KP0            82
 680 #define KEY_KPDOT        83
 681 
 682 #define KEY_ZENKAKUHANKAKU    85
 683 #define KEY_102ND        86
 684 #define KEY_F11            87
 685 #define KEY_F12            88
 686 #define KEY_RO            89
 687 #define KEY_KATAKANA        90
 688 #define KEY_HIRAGANA        91
 689 #define KEY_HENKAN        92
 690 #define KEY_KATAKANAHIRAGANA    93
 691 #define KEY_MUHENKAN        94
 692 #define KEY_KPJPCOMMA        95
 693 #define KEY_KPENTER        96
 694 #define KEY_RIGHTCTRL        97
 695 #define KEY_KPSLASH        98
 696 #define KEY_SYSRQ        99
 697 #define KEY_RIGHTALT        100
 698 #define KEY_LINEFEED        101
 699 #define KEY_HOME        102
 700 #define KEY_UP            103
 701 #define KEY_PAGEUP        104
 702 #define KEY_LEFT        105
 703 #define KEY_RIGHT        106
 704 #define KEY_END            107
 705 #define KEY_DOWN        108
 706 #define KEY_PAGEDOWN        109
 707 #define KEY_INSERT        110
 708 #define KEY_DELETE        111
 709 #define KEY_MACRO        112
 710 #define KEY_MUTE        113
 711 #define KEY_VOLUMEDOWN        114
 712 #define KEY_VOLUMEUP        115
 713 #define KEY_POWER        116    /* SC System Power Down */
 714 #define KEY_KPEQUAL        117
 715 #define KEY_KPPLUSMINUS        118
 716 #define KEY_PAUSE        119
 717 #define KEY_SCALE        120    /* AL Compiz Scale (Expose) */
 718 
 719 #define KEY_KPCOMMA        121
 720 #define KEY_HANGEUL        122
 721 #define KEY_HANGUEL        KEY_HANGEUL
 722 #define KEY_HANJA        123
 723 #define KEY_YEN            124
 724 #define KEY_LEFTMETA        125
 725 #define KEY_RIGHTMETA        126
 726 #define KEY_COMPOSE        127
 727 
 728 #define KEY_STOP        128    /* AC Stop */
 729 #define KEY_AGAIN        129
 730 #define KEY_PROPS        130    /* AC Properties */
 731 #define KEY_UNDO        131    /* AC Undo */
 732 #define KEY_FRONT        132
 733 #define KEY_COPY        133    /* AC Copy */
 734 #define KEY_OPEN        134    /* AC Open */
 735 #define KEY_PASTE        135    /* AC Paste */
 736 #define KEY_FIND        136    /* AC Search */
 737 #define KEY_CUT            137    /* AC Cut */
 738 #define KEY_HELP        138    /* AL Integrated Help Center */
 739 #define KEY_MENU        139    /* Menu (show menu) */
 740 #define KEY_CALC        140    /* AL Calculator */
 741 #define KEY_SETUP        141
 742 #define KEY_SLEEP        142    /* SC System Sleep */
 743 #define KEY_WAKEUP        143    /* System Wake Up */
 744 #define KEY_FILE        144    /* AL Local Machine Browser */
 745 #define KEY_SENDFILE        145
 746 #define KEY_DELETEFILE        146
 747 #define KEY_XFER        147
 748 #define KEY_PROG1        148
 749 #define KEY_PROG2        149
 750 #define KEY_WWW            150    /* AL Internet Browser */
 751 #define KEY_MSDOS        151
 752 #define KEY_COFFEE        152    /* AL Terminal Lock/Screensaver */
 753 #define KEY_SCREENLOCK        KEY_COFFEE
 754 #define KEY_DIRECTION        153
 755 #define KEY_CYCLEWINDOWS    154
 756 #define KEY_MAIL        155
 757 #define KEY_BOOKMARKS        156    /* AC Bookmarks */
 758 #define KEY_COMPUTER        157
 759 #define KEY_BACK        158    /* AC Back */
 760 #define KEY_FORWARD        159    /* AC Forward */
 761 #define KEY_CLOSECD        160
 762 #define KEY_EJECTCD        161
 763 #define KEY_EJECTCLOSECD    162
 764 #define KEY_NEXTSONG        163
 765 #define KEY_PLAYPAUSE        164
 766 #define KEY_PREVIOUSSONG    165
 767 #define KEY_STOPCD        166
 768 #define KEY_RECORD        167
 769 #define KEY_REWIND        168
 770 #define KEY_PHONE        169    /* Media Select Telephone */
 771 #define KEY_ISO            170
 772 #define KEY_CONFIG        171    /* AL Consumer Control Configuration */
 773 #define KEY_HOMEPAGE        172    /* AC Home */
 774 #define KEY_REFRESH        173    /* AC Refresh */
 775 #define KEY_EXIT        174    /* AC Exit */
 776 #define KEY_MOVE        175
 777 #define KEY_EDIT        176
 778 #define KEY_SCROLLUP        177
 779 #define KEY_SCROLLDOWN        178
 780 #define KEY_KPLEFTPAREN        179
 781 #define KEY_KPRIGHTPAREN    180
 782 #define KEY_NEW            181    /* AC New */
 783 #define KEY_REDO        182    /* AC Redo/Repeat */
 784 
 785 #define KEY_F13            183
 786 #define KEY_F14            184
 787 #define KEY_F15            185
 788 #define KEY_F16            186
 789 #define KEY_F17            187
 790 #define KEY_F18            188
 791 #define KEY_F19            189
 792 #define KEY_F20            190
 793 #define KEY_F21            191
 794 #define KEY_F22            192
 795 #define KEY_F23            193
 796 #define KEY_F24            194
 797 
 798 #define KEY_PLAYCD        200
 799 #define KEY_PAUSECD        201
 800 #define KEY_PROG3        202
 801 #define KEY_PROG4        203
 802 #define KEY_DASHBOARD        204    /* AL Dashboard */
 803 #define KEY_SUSPEND        205
 804 #define KEY_CLOSE        206    /* AC Close */
 805 #define KEY_PLAY        207
 806 #define KEY_FASTFORWARD        208
 807 #define KEY_BASSBOOST        209
 808 #define KEY_PRINT        210    /* AC Print */
 809 #define KEY_HP            211
 810 #define KEY_CAMERA        212
 811 #define KEY_SOUND        213
 812 #define KEY_QUESTION        214
 813 #define KEY_EMAIL        215
 814 #define KEY_CHAT        216
 815 #define KEY_SEARCH        217
 816 #define KEY_CONNECT        218
 817 #define KEY_FINANCE        219    /* AL Checkbook/Finance */
 818 #define KEY_SPORT        220
 819 #define KEY_SHOP        221
 820 #define KEY_ALTERASE        222
 821 #define KEY_CANCEL        223    /* AC Cancel */
 822 #define KEY_BRIGHTNESSDOWN    224
 823 #define KEY_BRIGHTNESSUP    225
 824 #define KEY_MEDIA        226
 825 
 826 #define KEY_SWITCHVIDEOMODE    227    /* Cycle between available video
 827                        outputs (Monitor/LCD/TV-out/etc) */
 828 #define KEY_KBDILLUMTOGGLE    228
 829 #define KEY_KBDILLUMDOWN    229
 830 #define KEY_KBDILLUMUP        230
 831 
 832 #define KEY_SEND        231    /* AC Send */
 833 #define KEY_REPLY        232    /* AC Reply */
 834 #define KEY_FORWARDMAIL        233    /* AC Forward Msg */
 835 #define KEY_SAVE        234    /* AC Save */
 836 #define KEY_DOCUMENTS        235
 837 
 838 #define KEY_BATTERY        236
 839 
 840 #define KEY_BLUETOOTH        237
 841 #define KEY_WLAN        238
 842 #define KEY_UWB            239
 843 
 844 #define KEY_UNKNOWN        240
 845 
 846 #define KEY_VIDEO_NEXT        241    /* drive next video source */
 847 #define KEY_VIDEO_PREV        242    /* drive previous video source */
 848 #define KEY_BRIGHTNESS_CYCLE    243    /* brightness up, after max is min */
 849 #define KEY_BRIGHTNESS_ZERO    244    /* brightness off, use ambient */
 850 #define KEY_DISPLAY_OFF        245    /* display device to off state */
 851 
 852 #define KEY_WIMAX        246
 853 #define KEY_RFKILL        247    /* Key that controls all radios */
 854 
 855 /* Code 255 is reserved for special needs of AT keyboard driver */
 856 
 857 #define BTN_MISC        0x100
 858 #define BTN_0            0x100
 859 #define BTN_1            0x101
 860 #define BTN_2            0x102
 861 #define BTN_3            0x103
 862 #define BTN_4            0x104
 863 #define BTN_5            0x105
 864 #define BTN_6            0x106
 865 #define BTN_7            0x107
 866 #define BTN_8            0x108
 867 #define BTN_9            0x109
 868 
 869 #define BTN_MOUSE        0x110
 870 #define BTN_LEFT        0x110
 871 #define BTN_RIGHT        0x111
 872 #define BTN_MIDDLE        0x112
 873 #define BTN_SIDE        0x113
 874 #define BTN_EXTRA        0x114
 875 #define BTN_FORWARD        0x115
 876 #define BTN_BACK        0x116
 877 #define BTN_TASK        0x117
 878 
 879 #define BTN_JOYSTICK        0x120
 880 #define BTN_TRIGGER        0x120
 881 #define BTN_THUMB        0x121
 882 #define BTN_THUMB2        0x122
 883 #define BTN_TOP            0x123
 884 #define BTN_TOP2        0x124
 885 #define BTN_PINKIE        0x125
 886 #define BTN_BASE        0x126
 887 #define BTN_BASE2        0x127
 888 #define BTN_BASE3        0x128
 889 #define BTN_BASE4        0x129
 890 #define BTN_BASE5        0x12a
 891 #define BTN_BASE6        0x12b
 892 #define BTN_DEAD        0x12f
 893 
 894 #define BTN_GAMEPAD        0x130
 895 #define BTN_A            0x130
 896 #define BTN_B            0x131
 897 #define BTN_C            0x132
 898 #define BTN_X            0x133
 899 #define BTN_Y            0x134
 900 #define BTN_Z            0x135
 901 #define BTN_TL            0x136
 902 #define BTN_TR            0x137
 903 #define BTN_TL2            0x138
 904 #define BTN_TR2            0x139
 905 #define BTN_SELECT        0x13a
 906 #define BTN_START        0x13b
 907 #define BTN_MODE        0x13c
 908 #define BTN_THUMBL        0x13d
 909 #define BTN_THUMBR        0x13e
 910 
 911 #define BTN_DIGI        0x140
 912 #define BTN_TOOL_PEN        0x140
 913 #define BTN_TOOL_RUBBER        0x141
 914 #define BTN_TOOL_BRUSH        0x142
 915 #define BTN_TOOL_PENCIL        0x143
 916 #define BTN_TOOL_AIRBRUSH    0x144
 917 #define BTN_TOOL_FINGER        0x145
 918 #define BTN_TOOL_MOUSE        0x146
 919 #define BTN_TOOL_LENS        0x147
 920 #define BTN_TOUCH        0x14a
 921 #define BTN_STYLUS        0x14b
 922 #define BTN_STYLUS2        0x14c
 923 #define BTN_TOOL_DOUBLETAP    0x14d
 924 #define BTN_TOOL_TRIPLETAP    0x14e
 925 #define BTN_TOOL_QUADTAP    0x14f    /* Four fingers on trackpad */
 926 
 927 #define BTN_WHEEL        0x150
 928 #define BTN_GEAR_DOWN        0x150
 929 #define BTN_GEAR_UP        0x151
 930 
 931 #define KEY_OK            0x160
 932 #define KEY_SELECT        0x161
 933 #define KEY_GOTO        0x162
 934 #define KEY_CLEAR        0x163
 935 #define KEY_POWER2        0x164
 936 #define KEY_OPTION        0x165
 937 #define KEY_INFO        0x166    /* AL OEM Features/Tips/Tutorial */
 938 #define KEY_TIME        0x167
 939 #define KEY_VENDOR        0x168
 940 #define KEY_ARCHIVE        0x169
 941 #define KEY_PROGRAM        0x16a    /* Media Select Program Guide */
 942 #define KEY_CHANNEL        0x16b
 943 #define KEY_FAVORITES        0x16c
 944 #define KEY_EPG            0x16d
 945 #define KEY_PVR            0x16e    /* Media Select Home */
 946 #define KEY_MHP            0x16f
 947 #define KEY_LANGUAGE        0x170
 948 #define KEY_TITLE        0x171
 949 #define KEY_SUBTITLE        0x172
 950 #define KEY_ANGLE        0x173
 951 #define KEY_ZOOM        0x174
 952 #define KEY_MODE        0x175
 953 #define KEY_KEYBOARD        0x176
 954 #define KEY_SCREEN        0x177
 955 #define KEY_PC            0x178    /* Media Select Computer */
 956 #define KEY_TV            0x179    /* Media Select TV */
 957 #define KEY_TV2            0x17a    /* Media Select Cable */
 958 #define KEY_VCR            0x17b    /* Media Select VCR */
 959 #define KEY_VCR2        0x17c    /* VCR Plus */
 960 #define KEY_SAT            0x17d    /* Media Select Satellite */
 961 #define KEY_SAT2        0x17e
 962 #define KEY_CD            0x17f    /* Media Select CD */
 963 #define KEY_TAPE        0x180    /* Media Select Tape */
 964 #define KEY_RADIO        0x181
 965 #define KEY_TUNER        0x182    /* Media Select Tuner */
 966 #define KEY_PLAYER        0x183
 967 #define KEY_TEXT        0x184
 968 #define KEY_DVD            0x185    /* Media Select DVD */
 969 #define KEY_AUX            0x186
 970 #define KEY_MP3            0x187
 971 #define KEY_AUDIO        0x188    /* AL Audio Browser */
 972 #define KEY_VIDEO        0x189    /* AL Movie Browser */
 973 #define KEY_DIRECTORY        0x18a
 974 #define KEY_LIST        0x18b
 975 #define KEY_MEMO        0x18c    /* Media Select Messages */
 976 #define KEY_CALENDAR        0x18d
 977 #define KEY_RED            0x18e
 978 #define KEY_GREEN        0x18f
 979 #define KEY_YELLOW        0x190
 980 #define KEY_BLUE        0x191
 981 #define KEY_CHANNELUP        0x192    /* Channel Increment */
 982 #define KEY_CHANNELDOWN        0x193    /* Channel Decrement */
 983 #define KEY_FIRST        0x194
 984 #define KEY_LAST        0x195    /* Recall Last */
 985 #define KEY_AB            0x196
 986 #define KEY_NEXT        0x197
 987 #define KEY_RESTART        0x198
 988 #define KEY_SLOW        0x199
 989 #define KEY_SHUFFLE        0x19a
 990 #define KEY_BREAK        0x19b
 991 #define KEY_PREVIOUS        0x19c
 992 #define KEY_DIGITS        0x19d
 993 #define KEY_TEEN        0x19e
 994 #define KEY_TWEN        0x19f
 995 #define KEY_VIDEOPHONE        0x1a0    /* Media Select Video Phone */
 996 #define KEY_GAMES        0x1a1    /* Media Select Games */
 997 #define KEY_ZOOMIN        0x1a2    /* AC Zoom In */
 998 #define KEY_ZOOMOUT        0x1a3    /* AC Zoom Out */
 999 #define KEY_ZOOMRESET        0x1a4    /* AC Zoom */
1000 #define KEY_WORDPROCESSOR    0x1a5    /* AL Word Processor */
1001 #define KEY_EDITOR        0x1a6    /* AL Text Editor */
1002 #define KEY_SPREADSHEET        0x1a7    /* AL Spreadsheet */
1003 #define KEY_GRAPHICSEDITOR    0x1a8    /* AL Graphics Editor */
1004 #define KEY_PRESENTATION    0x1a9    /* AL Presentation App */
1005 #define KEY_DATABASE        0x1aa    /* AL Database App */
1006 #define KEY_NEWS        0x1ab    /* AL Newsreader */
1007 #define KEY_VOICEMAIL        0x1ac    /* AL Voicemail */
1008 #define KEY_ADDRESSBOOK        0x1ad    /* AL Contacts/Address Book */
1009 #define KEY_MESSENGER        0x1ae    /* AL Instant Messaging */
1010 #define KEY_DISPLAYTOGGLE    0x1af    /* Turn display (LCD) on and off */
1011 #define KEY_SPELLCHECK        0x1b0   /* AL Spell Check */
1012 #define KEY_LOGOFF        0x1b1   /* AL Logoff */
1013 
1014 #define KEY_DOLLAR        0x1b2
1015 #define KEY_EURO        0x1b3
1016 
1017 #define KEY_FRAMEBACK        0x1b4    /* Consumer - transport controls */
1018 #define KEY_FRAMEFORWARD    0x1b5
1019 #define KEY_CONTEXT_MENU    0x1b6    /* GenDesc - system context menu */
1020 #define KEY_MEDIA_REPEAT    0x1b7    /* Consumer - transport control */
1021 #define KEY_10CHANNELSUP    0x1b8    /* 10 channels up (10+) */
1022 #define KEY_10CHANNELSDOWN    0x1b9    /* 10 channels down (10-) */
1023 #define KEY_IMAGES        0x1ba    /* AL Image Browser */
1024 
1025 #define KEY_DEL_EOL        0x1c0
1026 #define KEY_DEL_EOS        0x1c1
1027 #define KEY_INS_LINE        0x1c2
1028 #define KEY_DEL_LINE        0x1c3
1029 
1030 #define KEY_FN            0x1d0
1031 #define KEY_FN_ESC        0x1d1
1032 #define KEY_FN_F1        0x1d2
1033 #define KEY_FN_F2        0x1d3
1034 #define KEY_FN_F3        0x1d4
1035 #define KEY_FN_F4        0x1d5
1036 #define KEY_FN_F5        0x1d6
1037 #define KEY_FN_F6        0x1d7
1038 #define KEY_FN_F7        0x1d8
1039 #define KEY_FN_F8        0x1d9
1040 #define KEY_FN_F9        0x1da
1041 #define KEY_FN_F10        0x1db
1042 #define KEY_FN_F11        0x1dc
1043 #define KEY_FN_F12        0x1dd
1044 #define KEY_FN_1        0x1de
1045 #define KEY_FN_2        0x1df
1046 #define KEY_FN_D        0x1e0
1047 #define KEY_FN_E        0x1e1
1048 #define KEY_FN_F        0x1e2
1049 #define KEY_FN_S        0x1e3
1050 #define KEY_FN_B        0x1e4
1051 
1052 #define KEY_BRL_DOT1        0x1f1
1053 #define KEY_BRL_DOT2        0x1f2
1054 #define KEY_BRL_DOT3        0x1f3
1055 #define KEY_BRL_DOT4        0x1f4
1056 #define KEY_BRL_DOT5        0x1f5
1057 #define KEY_BRL_DOT6        0x1f6
1058 #define KEY_BRL_DOT7        0x1f7
1059 #define KEY_BRL_DOT8        0x1f8
1060 #define KEY_BRL_DOT9        0x1f9
1061 #define KEY_BRL_DOT10        0x1fa
1062 
1063 #define KEY_NUMERIC_0        0x200    /* used by phones, remote controls, */
1064 #define KEY_NUMERIC_1        0x201    /* and other keypads */
1065 #define KEY_NUMERIC_2        0x202
1066 #define KEY_NUMERIC_3        0x203
1067 #define KEY_NUMERIC_4        0x204
1068 #define KEY_NUMERIC_5        0x205
1069 #define KEY_NUMERIC_6        0x206
1070 #define KEY_NUMERIC_7        0x207
1071 #define KEY_NUMERIC_8        0x208
1072 #define KEY_NUMERIC_9        0x209
1073 #define KEY_NUMERIC_STAR    0x20a
1074 #define KEY_NUMERIC_POUND    0x20b
1075 
1076 #define KEY_CAMERA_FOCUS    0x210
1077 #define KEY_WPS_BUTTON        0x211    /* WiFi Protected Setup key */
1078 
1079 #define KEY_TOUCHPAD_TOGGLE    0x212    /* Request switch touchpad on or off */
1080 #define KEY_TOUCHPAD_ON        0x213
1081 #define KEY_TOUCHPAD_OFF    0x214
1082 
1083 #define KEY_CAMERA_ZOOMIN    0x215
1084 #define KEY_CAMERA_ZOOMOUT    0x216
1085 #define KEY_CAMERA_UP        0x217
1086 #define KEY_CAMERA_DOWN        0x218
1087 #define KEY_CAMERA_LEFT        0x219
1088 #define KEY_CAMERA_RIGHT    0x21a
1089 
1090 #define BTN_TRIGGER_HAPPY        0x2c0
1091 #define BTN_TRIGGER_HAPPY1        0x2c0
1092 #define BTN_TRIGGER_HAPPY2        0x2c1
1093 #define BTN_TRIGGER_HAPPY3        0x2c2
1094 #define BTN_TRIGGER_HAPPY4        0x2c3
1095 #define BTN_TRIGGER_HAPPY5        0x2c4
1096 #define BTN_TRIGGER_HAPPY6        0x2c5
1097 #define BTN_TRIGGER_HAPPY7        0x2c6
1098 #define BTN_TRIGGER_HAPPY8        0x2c7
1099 #define BTN_TRIGGER_HAPPY9        0x2c8
1100 #define BTN_TRIGGER_HAPPY10        0x2c9
1101 #define BTN_TRIGGER_HAPPY11        0x2ca
1102 #define BTN_TRIGGER_HAPPY12        0x2cb
1103 #define BTN_TRIGGER_HAPPY13        0x2cc
1104 #define BTN_TRIGGER_HAPPY14        0x2cd
1105 #define BTN_TRIGGER_HAPPY15        0x2ce
1106 #define BTN_TRIGGER_HAPPY16        0x2cf
1107 #define BTN_TRIGGER_HAPPY17        0x2d0
1108 #define BTN_TRIGGER_HAPPY18        0x2d1
1109 #define BTN_TRIGGER_HAPPY19        0x2d2
1110 #define BTN_TRIGGER_HAPPY20        0x2d3
1111 #define BTN_TRIGGER_HAPPY21        0x2d4
1112 #define BTN_TRIGGER_HAPPY22        0x2d5
1113 #define BTN_TRIGGER_HAPPY23        0x2d6
1114 #define BTN_TRIGGER_HAPPY24        0x2d7
1115 #define BTN_TRIGGER_HAPPY25        0x2d8
1116 #define BTN_TRIGGER_HAPPY26        0x2d9
1117 #define BTN_TRIGGER_HAPPY27        0x2da
1118 #define BTN_TRIGGER_HAPPY28        0x2db
1119 #define BTN_TRIGGER_HAPPY29        0x2dc
1120 #define BTN_TRIGGER_HAPPY30        0x2dd
1121 #define BTN_TRIGGER_HAPPY31        0x2de
1122 #define BTN_TRIGGER_HAPPY32        0x2df
1123 #define BTN_TRIGGER_HAPPY33        0x2e0
1124 #define BTN_TRIGGER_HAPPY34        0x2e1
1125 #define BTN_TRIGGER_HAPPY35        0x2e2
1126 #define BTN_TRIGGER_HAPPY36        0x2e3
1127 #define BTN_TRIGGER_HAPPY37        0x2e4
1128 #define BTN_TRIGGER_HAPPY38        0x2e5
1129 #define BTN_TRIGGER_HAPPY39        0x2e6
1130 #define BTN_TRIGGER_HAPPY40        0x2e7
1131 
1132 /* We avoid low common keys in module aliases so they don't get huge. */
1133 #define KEY_MIN_INTERESTING    KEY_MUTE
1134 #define KEY_MAX            0x2ff
1135 #define KEY_CNT            (KEY_MAX+1)
1136 
1137 /*
1138  * Relative axes
1139  */
1140 
1141 #define REL_X            0x00
1142 #define REL_Y            0x01
1143 #define REL_Z            0x02
1144 #define REL_RX            0x03
1145 #define REL_RY            0x04
1146 #define REL_RZ            0x05
1147 #define REL_HWHEEL        0x06
1148 #define REL_DIAL        0x07
1149 #define REL_WHEEL        0x08
1150 #define REL_MISC        0x09
1151 #define REL_MAX            0x0f
1152 #define REL_CNT            (REL_MAX+1)
1153 
1154 /*
1155  * Absolute axes
1156  */
1157 
1158 #define ABS_X            0x00
1159 #define ABS_Y            0x01
1160 #define ABS_Z            0x02
1161 #define ABS_RX            0x03
1162 #define ABS_RY            0x04
1163 #define ABS_RZ            0x05
1164 #define ABS_THROTTLE        0x06
1165 #define ABS_RUDDER        0x07
1166 #define ABS_WHEEL        0x08
1167 #define ABS_GAS            0x09
1168 #define ABS_BRAKE        0x0a
1169 #define ABS_HAT0X        0x10
1170 #define ABS_HAT0Y        0x11
1171 #define ABS_HAT1X        0x12
1172 #define ABS_HAT1Y        0x13
1173 #define ABS_HAT2X        0x14
1174 #define ABS_HAT2Y        0x15
1175 #define ABS_HAT3X        0x16
1176 #define ABS_HAT3Y        0x17
1177 #define ABS_PRESSURE        0x18
1178 #define ABS_DISTANCE        0x19
1179 #define ABS_TILT_X        0x1a
1180 #define ABS_TILT_Y        0x1b
1181 #define ABS_TOOL_WIDTH        0x1c
1182 
1183 #define ABS_VOLUME        0x20
1184 
1185 #define ABS_MISC        0x28
1186 
1187 #define ABS_MT_SLOT        0x2f    /* MT slot being modified */
1188 #define ABS_MT_TOUCH_MAJOR    0x30    /* Major axis of touching ellipse */
1189 #define ABS_MT_TOUCH_MINOR    0x31    /* Minor axis (omit if circular) */
1190 #define ABS_MT_WIDTH_MAJOR    0x32    /* Major axis of approaching ellipse */
1191 #define ABS_MT_WIDTH_MINOR    0x33    /* Minor axis (omit if circular) */
1192 #define ABS_MT_ORIENTATION    0x34    /* Ellipse orientation */
1193 #define ABS_MT_POSITION_X    0x35    /* Center X ellipse position */
1194 #define ABS_MT_POSITION_Y    0x36    /* Center Y ellipse position */
1195 #define ABS_MT_TOOL_TYPE    0x37    /* Type of touching device */
1196 #define ABS_MT_BLOB_ID        0x38    /* Group a set of packets as a blob */
1197 #define ABS_MT_TRACKING_ID    0x39    /* Unique ID of initiated contact */
1198 #define ABS_MT_PRESSURE        0x3a    /* Pressure on contact area */
1199 #define ABS_MT_DISTANCE        0x3b    /* Contact hover distance */
1200 
1201 #ifdef __KERNEL__
1202 /* Implementation details, userspace should not care about these */
1203 #define ABS_MT_FIRST        ABS_MT_TOUCH_MAJOR
1204 #define ABS_MT_LAST        ABS_MT_DISTANCE
1205 #endif
1206 
1207 #define ABS_MAX            0x3f
1208 #define ABS_CNT            (ABS_MAX+1)
1209 
1210 /*
1211  * Switch events
1212  */
1213 
1214 #define SW_LID            0x00  /* set = lid shut */
1215 #define SW_TABLET_MODE        0x01  /* set = tablet mode */
1216 #define SW_HEADPHONE_INSERT    0x02  /* set = inserted */
1217 #define SW_RFKILL_ALL        0x03  /* rfkill master switch, type "any"
1218                      set = radio enabled */
1219 #define SW_RADIO        SW_RFKILL_ALL    /* deprecated */
1220 #define SW_MICROPHONE_INSERT    0x04  /* set = inserted */
1221 #define SW_DOCK            0x05  /* set = plugged into dock */
1222 #define SW_LINEOUT_INSERT    0x06  /* set = inserted */
1223 #define SW_JACK_PHYSICAL_INSERT 0x07  /* set = mechanical switch set */
1224 #define SW_VIDEOOUT_INSERT    0x08  /* set = inserted */
1225 #define SW_CAMERA_LENS_COVER    0x09  /* set = lens covered */
1226 #define SW_KEYPAD_SLIDE        0x0a  /* set = keypad slide out */
1227 #define SW_FRONT_PROXIMITY    0x0b  /* set = front proximity sensor active */
1228 #define SW_ROTATE_LOCK        0x0c  /* set = rotate locked/disabled */
1229 #define SW_MAX            0x0f
1230 #define SW_CNT            (SW_MAX+1)
1231 
1232 /*
1233  * Misc events
1234  */
1235 
1236 #define MSC_SERIAL        0x00
1237 #define MSC_PULSELED        0x01
1238 #define MSC_GESTURE        0x02
1239 #define MSC_RAW            0x03
1240 #define MSC_SCAN        0x04
1241 #define MSC_MAX            0x07
1242 #define MSC_CNT            (MSC_MAX+1)
1243 
1244 /*
1245  * LEDs
1246  */
1247 
1248 #define LED_NUML        0x00
1249 #define LED_CAPSL        0x01
1250 #define LED_SCROLLL        0x02
1251 #define LED_COMPOSE        0x03
1252 #define LED_KANA        0x04
1253 #define LED_SLEEP        0x05
1254 #define LED_SUSPEND        0x06
1255 #define LED_MUTE        0x07
1256 #define LED_MISC        0x08
1257 #define LED_MAIL        0x09
1258 #define LED_CHARGING        0x0a
1259 #define LED_MAX            0x0f
1260 #define LED_CNT            (LED_MAX+1)
1261 
1262 /*
1263  * Autorepeat values
1264  */
1265 
1266 #define REP_DELAY        0x00
1267 #define REP_PERIOD        0x01
1268 #define REP_MAX            0x01
1269 #define REP_CNT            (REP_MAX+1)
1270 
1271 /*
1272  * Sounds
1273  */
1274 
1275 #define SND_CLICK        0x00
1276 #define SND_BELL        0x01
1277 #define SND_TONE        0x02
1278 #define SND_MAX            0x07
1279 #define SND_CNT            (SND_MAX+1)
1280 
1281 /*
1282  * IDs.
1283  */
1284 
1285 #define ID_BUS            0
1286 #define ID_VENDOR        1
1287 #define ID_PRODUCT        2
1288 #define ID_VERSION        3
1289 
1290 #define BUS_PCI            0x01
1291 #define BUS_ISAPNP        0x02
1292 #define BUS_USB            0x03
1293 #define BUS_HIL            0x04
1294 #define BUS_BLUETOOTH        0x05
1295 #define BUS_VIRTUAL        0x06
1296 
1297 #define BUS_ISA            0x10
1298 #define BUS_I8042        0x11
1299 #define BUS_XTKBD        0x12
1300 #define BUS_RS232        0x13
1301 #define BUS_GAMEPORT        0x14
1302 #define BUS_PARPORT        0x15
1303 #define BUS_AMIGA        0x16
1304 #define BUS_ADB            0x17
1305 #define BUS_I2C            0x18
1306 #define BUS_HOST        0x19
1307 #define BUS_GSC            0x1A
1308 #define BUS_ATARI        0x1B
1309 #define BUS_SPI            0x1C
1310 
1311 /*
1312  * MT_TOOL types
1313  */
1314 #define MT_TOOL_FINGER        0
1315 #define MT_TOOL_PEN        1
1316 #define MT_TOOL_MAX        1
1317 
1318 /*
1319  * Values describing the status of a force-feedback effect
1320  */
1321 #define FF_STATUS_STOPPED    0x00
1322 #define FF_STATUS_PLAYING    0x01
1323 #define FF_STATUS_MAX        0x01
1324 
1325 /*
1326  * Structures used in ioctls to upload effects to a device
1327  * They are pieces of a bigger structure (called ff_effect)
1328  */
1329 
1330 /*
1331  * All duration values are expressed in ms. Values above 32767 ms (0x7fff)
1332  * should not be used and have unspecified results.
1333  */
1334 
1335 /**
1336  * struct ff_replay - defines scheduling of the force-feedback effect
1337  * @length: duration of the effect
1338  * @delay: delay before effect should start playing
1339  */
1340 struct ff_replay {
1341     __u16 length;
1342     __u16 delay;
1343 };
1344 
1345 /**
1346  * struct ff_trigger - defines what triggers the force-feedback effect
1347  * @button: number of the button triggering the effect
1348  * @interval: controls how soon the effect can be re-triggered
1349  */
1350 struct ff_trigger {
1351     __u16 button;
1352     __u16 interval;
1353 };
1354 
1355 /**
1356  * struct ff_envelope - generic force-feedback effect envelope
1357  * @attack_length: duration of the attack (ms)
1358  * @attack_level: level at the beginning of the attack
1359  * @fade_length: duration of fade (ms)
1360  * @fade_level: level at the end of fade
1361  *
1362  * The @attack_level and @fade_level are absolute values; when applying
1363  * envelope force-feedback core will convert to positive/negative
1364  * value based on polarity of the default level of the effect.
1365  * Valid range for the attack and fade levels is 0x0000 - 0x7fff
1366  */
1367 struct ff_envelope {
1368     __u16 attack_length;
1369     __u16 attack_level;
1370     __u16 fade_length;
1371     __u16 fade_level;
1372 };
1373 
1374 /**
1375  * struct ff_constant_effect - defines parameters of a constant force-feedback effect
1376  * @level: strength of the effect; may be negative
1377  * @envelope: envelope data
1378  */
1379 struct ff_constant_effect {
1380     __s16 level;
1381     struct ff_envelope envelope;
1382 };
1383 
1384 /**
1385  * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
1386  * @start_level: beginning strength of the effect; may be negative
1387  * @end_level: final strength of the effect; may be negative
1388  * @envelope: envelope data
1389  */
1390 struct ff_ramp_effect {
1391     __s16 start_level;
1392     __s16 end_level;
1393     struct ff_envelope envelope;
1394 };
1395 
1396 /**
1397  * struct ff_condition_effect - defines a spring or friction force-feedback effect
1398  * @right_saturation: maximum level when joystick moved all way to the right
1399  * @left_saturation: same for the left side
1400  * @right_coeff: controls how fast the force grows when the joystick moves
1401  *    to the right
1402  * @left_coeff: same for the left side
1403  * @deadband: size of the dead zone, where no force is produced
1404  * @center: position of the dead zone
1405  */
1406 struct ff_condition_effect {
1407     __u16 right_saturation;
1408     __u16 left_saturation;
1409 
1410     __s16 right_coeff;
1411     __s16 left_coeff;
1412 
1413     __u16 deadband;
1414     __s16 center;
1415 };
1416 
1417 /**
1418  * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
1419  * @waveform: kind of the effect (wave)
1420  * @period: period of the wave (ms)
1421  * @magnitude: peak value
1422  * @offset: mean value of the wave (roughly)
1423  * @phase: 'horizontal' shift
1424  * @envelope: envelope data
1425  * @custom_len: number of samples (FF_CUSTOM only)
1426  * @custom_data: buffer of samples (FF_CUSTOM only)
1427  *
1428  * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
1429  * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
1430  * for the time being as no driver supports it yet.
1431  *
1432  * Note: the data pointed by custom_data is copied by the driver.
1433  * You can therefore dispose of the memory after the upload/update.
1434  */
1435 struct ff_periodic_effect {
1436     __u16 waveform;
1437     __u16 period;
1438     __s16 magnitude;
1439     __s16 offset;
1440     __u16 phase;
1441 
1442     struct ff_envelope envelope;
1443 
1444     __u32 custom_len;
1445     __s16 __user *custom_data;
1446 };
1447 
1448 /**
1449  * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
1450  * @strong_magnitude: magnitude of the heavy motor
1451  * @weak_magnitude: magnitude of the light one
1452  *
1453  * Some rumble pads have two motors of different weight. Strong_magnitude
1454  * represents the magnitude of the vibration generated by the heavy one.
1455  */
1456 struct ff_rumble_effect {
1457     __u16 strong_magnitude;
1458     __u16 weak_magnitude;
1459 };
1460 
1461 /**
1462  * struct ff_effect - defines force feedback effect
1463  * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
1464  *    FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
1465  * @id: an unique id assigned to an effect
1466  * @direction: direction of the effect
1467  * @trigger: trigger conditions (struct ff_trigger)
1468  * @replay: scheduling of the effect (struct ff_replay)
1469  * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
1470  *    ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
1471  *    defining effect parameters
1472  *
1473  * This structure is sent through ioctl from the application to the driver.
1474  * To create a new effect application should set its @id to -1; the kernel
1475  * will return assigned @id which can later be used to update or delete
1476  * this effect.
1477  *
1478  * Direction of the effect is encoded as follows:
1479  *    0 deg -> 0x0000 (down)
1480  *    90 deg -> 0x4000 (left)
1481  *    180 deg -> 0x8000 (up)
1482  *    270 deg -> 0xC000 (right)
1483  */
1484 struct ff_effect {
1485     __u16 type;
1486     __s16 id;
1487     __u16 direction;
1488     struct ff_trigger trigger;
1489     struct ff_replay replay;
1490 
1491     union {
1492         struct ff_constant_effect constant;
1493         struct ff_ramp_effect ramp;
1494         struct ff_periodic_effect periodic;
1495         struct ff_condition_effect condition[2]; /* One for each axis */
1496         struct ff_rumble_effect rumble;
1497     } u;
1498 };
1499 
1500 /*
1501  * Force feedback effect types
1502  */
1503 
1504 #define FF_RUMBLE    0x50
1505 #define FF_PERIODIC    0x51
1506 #define FF_CONSTANT    0x52
1507 #define FF_SPRING    0x53
1508 #define FF_FRICTION    0x54
1509 #define FF_DAMPER    0x55
1510 #define FF_INERTIA    0x56
1511 #define FF_RAMP        0x57
1512 
1513 #define FF_EFFECT_MIN    FF_RUMBLE
1514 #define FF_EFFECT_MAX    FF_RAMP
1515 
1516 /*
1517  * Force feedback periodic effect types
1518  */
1519 
1520 #define FF_SQUARE    0x58
1521 #define FF_TRIANGLE    0x59
1522 #define FF_SINE        0x5a
1523 #define FF_SAW_UP    0x5b
1524 #define FF_SAW_DOWN    0x5c
1525 #define FF_CUSTOM    0x5d
1526 
1527 #define FF_WAVEFORM_MIN    FF_SQUARE
1528 #define FF_WAVEFORM_MAX    FF_CUSTOM
1529 
1530 /*
1531  * Set ff device properties
1532  */
1533 
1534 #define FF_GAIN        0x60
1535 #define FF_AUTOCENTER    0x61
1536 
1537 #define FF_MAX        0x7f
1538 #define FF_CNT        (FF_MAX+1)
1539 
1540 #ifdef __KERNEL__
1541 
1542 /*
1543  * In-kernel definitions.
1544  */
1545 
1546 #include <linux/device.h>
1547 #include <linux/fs.h>
1548 #include <linux/timer.h>
1549 #include <linux/mod_devicetable.h>
1550 
1551 /**
1552  * struct input_dev - represents an input device
1553  * @name: name of the device
1554  * @phys: physical path to the device in the system hierarchy
1555  * @uniq: unique identification code for the device (if device has it)
1556  * @id: id of the device (struct input_id)
1557  * @propbit: bitmap of device properties and quirks
1558  * @evbit: bitmap of types of events supported by the device (EV_KEY,
1559  *    EV_REL, etc.)
1560  * @keybit: bitmap of keys/buttons this device has
1561  * @relbit: bitmap of relative axes for the device
1562  * @absbit: bitmap of absolute axes for the device
1563  * @mscbit: bitmap of miscellaneous events supported by the device
1564  * @ledbit: bitmap of leds present on the device
1565  * @sndbit: bitmap of sound effects supported by the device
1566  * @ffbit: bitmap of force feedback effects supported by the device
1567  * @swbit: bitmap of switches present on the device
1568  * @hint_events_per_packet: average number of events generated by the
1569  *    device in a packet (between EV_SYN/SYN_REPORT events). Used by
1570  *    event handlers to estimate size of the buffer needed to hold
1571  *    events.
1572  * @keycodemax: size of keycode table
1573  * @keycodesize: size of elements in keycode table
1574  * @keycode: map of scancodes to keycodes for this device
1575  * @getkeycode: optional legacy method to retrieve current keymap.
1576  * @setkeycode: optional method to alter current keymap, used to implement
1577  *    sparse keymaps. If not supplied default mechanism will be used.
1578  *    The method is being called while holding event_lock and thus must
1579  *    not sleep
1580  * @ff: force feedback structure associated with the device if device
1581  *    supports force feedback effects
1582  * @repeat_key: stores key code of the last key pressed; used to implement
1583  *    software autorepeat
1584  * @timer: timer for software autorepeat
1585  * @rep: current values for autorepeat parameters (delay, rate)
1586  * @mt: pointer to array of struct input_mt_slot holding current values
1587  *    of tracked contacts
1588  * @mtsize: number of MT slots the device uses
1589  * @slot: MT slot currently being transmitted
1590  * @trkid: stores MT tracking ID for the current contact
1591  * @absinfo: array of &struct input_absinfo elements holding information
1592  *    about absolute axes (current value, min, max, flat, fuzz,
1593  *    resolution)
1594  * @key: reflects current state of device's keys/buttons
1595  * @led: reflects current state of device's LEDs
1596  * @snd: reflects current state of sound effects
1597  * @sw: reflects current state of device's switches
1598  * @open: this method is called when the very first user calls
1599  *    input_open_device(). The driver must prepare the device
1600  *    to start generating events (start polling thread,
1601  *    request an IRQ, submit URB, etc.)
1602  * @close: this method is called when the very last user calls
1603  *    input_close_device().
1604  * @flush: purges the device. Most commonly used to get rid of force
1605  *    feedback effects loaded into the device when disconnecting
1606  *    from it
1607  * @event: event handler for events sent _to_ the device, like EV_LED
1608  *    or EV_SND. The device is expected to carry out the requested
1609  *    action (turn on a LED, play sound, etc.) The call is protected
1610  *    by @event_lock and must not sleep
1611  * @grab: input handle that currently has the device grabbed (via
1612  *    EVIOCGRAB ioctl). When a handle grabs a device it becomes sole
1613  *    recipient for all input events coming from the device
1614  * @event_lock: this spinlock is is taken when input core receives
1615  *    and processes a new event for the device (in input_event()).
1616  *    Code that accesses and/or modifies parameters of a device
1617  *    (such as keymap or absmin, absmax, absfuzz, etc.) after device
1618  *    has been registered with input core must take this lock.
1619  * @mutex: serializes calls to open(), close() and flush() methods
1620  * @users: stores number of users (input handlers) that opened this
1621  *    device. It is used by input_open_device() and input_close_device()
1622  *    to make sure that dev->open() is only called when the first
1623  *    user opens device and dev->close() is called when the very
1624  *    last user closes the device
1625  * @going_away: marks devices that are in a middle of unregistering and
1626  *    causes input_open_device*() fail with -ENODEV.
1627  * @sync: set to %true when there were no new events since last EV_SYN
1628  * @dev: driver model's view of this device
1629  * @h_list: list of input handles associated with the device. When
1630  *    accessing the list dev->mutex must be held
1631  * @node: used to place the device onto input_dev_list
1632  */
1633 struct input_dev {
1634     const char *name;
1635     const char *phys;
1636     const char *uniq;
1637     struct input_id id;
1638 
1639     unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
1640 
1641     unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
1642     unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
1643     unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
1644     unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
1645     unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
1646     unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
1647     unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
1648     unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
1649     unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
1650 
1651     unsigned int hint_events_per_packet;
1652 
1653     unsigned int keycodemax;
1654     unsigned int keycodesize;
1655     void *keycode;
1656 
1657     int (*setkeycode)(struct input_dev *dev,
1658               const struct input_keymap_entry *ke,
1659               unsigned int *old_keycode);
1660     int (*getkeycode)(struct input_dev *dev,
1661               struct input_keymap_entry *ke);
1662 
1663     struct ff_device *ff;
1664 
1665     unsigned int repeat_key;
1666     struct timer_list timer;
1667 
1668     int rep[REP_CNT];
1669 
1670     struct input_mt_slot *mt;
1671     int mtsize;
1672     int slot;
1673     int trkid;
1674 
1675     struct input_absinfo *absinfo;
1676 
1677     unsigned long key[BITS_TO_LONGS(KEY_CNT)];
1678     unsigned long led[BITS_TO_LONGS(LED_CNT)];
1679     unsigned long snd[BITS_TO_LONGS(SND_CNT)];
1680     unsigned long sw[BITS_TO_LONGS(SW_CNT)];
1681 
1682     int (*open)(struct input_dev *dev);
1683     void (*close)(struct input_dev *dev);
1684     int (*flush)(struct input_dev *dev, struct file *file);
1685     int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1686 
1687     struct input_handle __rcu *grab;
1688 
1689     spinlock_t event_lock;
1690     struct mutex mutex;
1691 
1692     unsigned int users;
1693     bool going_away;
1694 
1695     bool sync;
1696 
1697     struct device dev;
1698 
1699     struct list_head    h_list;
1700     struct list_head    node;
1701 };
1702 #define to_input_dev(d) container_of(d, struct input_dev, dev)
1703 
1704 /*
1705  * Verify that we are in sync with input_device_id mod_devicetable.h #defines
1706  */
1707 
1708 #if EV_MAX != INPUT_DEVICE_ID_EV_MAX
1709 #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
1710 #endif
1711 
1712 #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
1713 #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
1714 #endif
1715 
1716 #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
1717 #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
1718 #endif
1719 
1720 #if REL_MAX != INPUT_DEVICE_ID_REL_MAX
1721 #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
1722 #endif
1723 
1724 #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
1725 #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
1726 #endif
1727 
1728 #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
1729 #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
1730 #endif
1731 
1732 #if LED_MAX != INPUT_DEVICE_ID_LED_MAX
1733 #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
1734 #endif
1735 
1736 #if SND_MAX != INPUT_DEVICE_ID_SND_MAX
1737 #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
1738 #endif
1739 
1740 #if FF_MAX != INPUT_DEVICE_ID_FF_MAX
1741 #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
1742 #endif
1743 
1744 #if SW_MAX != INPUT_DEVICE_ID_SW_MAX
1745 #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
1746 #endif
1747 
1748 #define INPUT_DEVICE_ID_MATCH_DEVICE \
1749     (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
1750 #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
1751     (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
1752 
1753 struct input_handle;
1754 
1755 /**
1756  * struct input_handler - implements one of interfaces for input devices
1757  * @private: driver-specific data
1758  * @event: event handler. This method is being called by input core with
1759  *    interrupts disabled and dev->event_lock spinlock held and so
1760  *    it may not sleep
1761  * @filter: similar to @event; separates normal event handlers from
1762  *    "filters".
1763  * @match: called after comparing device's id with handler's id_table
1764  *    to perform fine-grained matching between device and handler
1765  * @connect: called when attaching a handler to an input device
1766  * @disconnect: disconnects a handler from input device
1767  * @start: starts handler for given handle. This function is called by
1768  *    input core right after connect() method and also when a process
1769  *    that "grabbed" a device releases it
1770  * @fops: file operations this driver implements
1771  * @minor: beginning of range of 32 minors for devices this driver
1772  *    can provide
1773  * @name: name of the handler, to be shown in /proc/bus/input/handlers
1774  * @id_table: pointer to a table of input_device_ids this driver can
1775  *    handle
1776  * @h_list: list of input handles associated with the handler
1777  * @node: for placing the driver onto input_handler_list
1778  *
1779  * Input handlers attach to input devices and create input handles. There
1780  * are likely several handlers attached to any given input device at the
1781  * same time. All of them will get their copy of input event generated by
1782  * the device.
1783  *
1784  * The very same structure is used to implement input filters. Input core
1785  * allows filters to run first and will not pass event to regular handlers
1786  * if any of the filters indicate that the event should be filtered (by
1787  * returning %true from their filter() method).
1788  *
1789  * Note that input core serializes calls to connect() and disconnect()
1790  * methods.
1791  */
1792 struct input_handler {
1793 
1794     void *private;
1795 
1796     void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1797     bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1798     bool (*match)(struct input_handler *handler, struct input_dev *dev);
1799     int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
1800     void (*disconnect)(struct input_handle *handle);
1801     void (*start)(struct input_handle *handle);
1802 
1803     const struct file_operations *fops;
1804     int minor;
1805     const char *name;
1806 
1807     const struct input_device_id *id_table;
1808 
1809     struct list_head    h_list;
1810     struct list_head    node;
1811 };
1812 
1813 /**
1814  * struct input_handle - links input device with an input handler
1815  * @private: handler-specific data
1816  * @open: counter showing whether the handle is 'open', i.e. should deliver
1817  *    events from its device
1818  * @name: name given to the handle by handler that created it
1819  * @dev: input device the handle is attached to
1820  * @handler: handler that works with the device through this handle
1821  * @d_node: used to put the handle on device's list of attached handles
1822  * @h_node: used to put the handle on handler's list of handles from which
1823  *    it gets events
1824  */
1825 struct input_handle {
1826 
1827     void *private;
1828 
1829     int open;
1830     const char *name;
1831 
1832     struct input_dev *dev;
1833     struct input_handler *handler;
1834 
1835     struct list_head    d_node;
1836     struct list_head    h_node;
1837 };
1838 
1839 struct input_dev *input_allocate_device(void);
1840 void input_free_device(struct input_dev *dev);
1841 
1842 static inline struct input_dev *input_get_device(struct input_dev *dev)
1843 {
1844     return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
1845 }
1846 
1847 static inline void input_put_device(struct input_dev *dev)
1848 {
1849     if (dev)
1850         put_device(&dev->dev);
1851 }
1852 
1853 static inline void *input_get_drvdata(struct input_dev *dev)
1854 {
1855     return dev_get_drvdata(&dev->dev);
1856 }
1857 
1858 static inline void input_set_drvdata(struct input_dev *dev, void *data)
1859 {
1860     dev_set_drvdata(&dev->dev, data);
1861 }
1862 
1863 int __must_check input_register_device(struct input_dev *);
1864 void input_unregister_device(struct input_dev *);
1865 
1866 void input_reset_device(struct input_dev *);
1867 
1868 int __must_check input_register_handler(struct input_handler *);
1869 void input_unregister_handler(struct input_handler *);
1870 
1871 int input_handler_for_each_handle(struct input_handler *, void *data,
1872                   int (*fn)(struct input_handle *, void *));
1873 
1874 int input_register_handle(struct input_handle *);
1875 void input_unregister_handle(struct input_handle *);
1876 
1877 int input_grab_device(struct input_handle *);
1878 void input_release_device(struct input_handle *);
1879 
1880 int input_open_device(struct input_handle *);
1881 void input_close_device(struct input_handle *);
1882 
1883 int input_flush_device(struct input_handle *handle, struct file *file);
1884 
1885 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1886 void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1887 
1888 static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
1889 {
1890     input_event(dev, EV_KEY, code, !!value);
1891 }
1892 
1893 static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
1894 {
1895     input_event(dev, EV_REL, code, value);
1896 }
1897 
1898 static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
1899 {
1900     input_event(dev, EV_ABS, code, value);
1901 }
1902 
1903 static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
1904 {
1905     input_event(dev, EV_FF_STATUS, code, value);
1906 }
1907 
1908 static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
1909 {
1910     input_event(dev, EV_SW, code, !!value);
1911 }
1912 
1913 static inline void input_sync(struct input_dev *dev)
1914 {
1915     input_event(dev, EV_SYN, SYN_REPORT, 0);
1916 }
1917 
1918 static inline void input_mt_sync(struct input_dev *dev)
1919 {
1920     input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
1921 }
1922 
1923 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
1924 
1925 /**
1926  * input_set_events_per_packet - tell handlers about the driver event rate
1927  * @dev: the input device used by the driver
1928  * @n_events: the average number of events between calls to input_sync()
1929  *
1930  * If the event rate sent from a device is unusually large, use this
1931  * function to set the expected event rate. This will allow handlers
1932  * to set up an appropriate buffer size for the event stream, in order
1933  * to minimize information loss.
1934  */
1935 static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
1936 {
1937     dev->hint_events_per_packet = n_events;
1938 }
1939 
1940 void input_alloc_absinfo(struct input_dev *dev);
1941 void input_set_abs_params(struct input_dev *dev, unsigned int axis,
1942               int min, int max, int fuzz, int flat);
1943 
1944 #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)            \
1945 static inline int input_abs_get_##_suffix(struct input_dev *dev,    \
1946                       unsigned int axis)        \
1947 {                                    \
1948     return dev->absinfo ? dev->absinfo[axis]._item : 0;        \
1949 }                                    \
1950                                     \
1951 static inline void input_abs_set_##_suffix(struct input_dev *dev,    \
1952                        unsigned int axis, int val)    \
1953 {                                    \
1954     input_alloc_absinfo(dev);                    \
1955     if (dev->absinfo)                        \
1956         dev->absinfo[axis]._item = val;                \
1957 }
1958 
1959 INPUT_GENERATE_ABS_ACCESSORS(val, value)
1960 INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
1961 INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
1962 INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
1963 INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
1964 INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
1965 
1966 int input_scancode_to_scalar(const struct input_keymap_entry *ke,
1967                  unsigned int *scancode);
1968 
1969 int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
1970 int input_set_keycode(struct input_dev *dev,
1971               const struct input_keymap_entry *ke);
1972 
1973 extern struct class input_class;
1974 
1975 /**
1976  * struct ff_device - force-feedback part of an input device
1977  * @upload: Called to upload an new effect into device
1978  * @erase: Called to erase an effect from device
1979  * @playback: Called to request device to start playing specified effect
1980  * @set_gain: Called to set specified gain
1981  * @set_autocenter: Called to auto-center device
1982  * @destroy: called by input core when parent input device is being
1983  *    destroyed
1984  * @private: driver-specific data, will be freed automatically
1985  * @ffbit: bitmap of force feedback capabilities truly supported by
1986  *    device (not emulated like ones in input_dev->ffbit)
1987  * @mutex: mutex for serializing access to the device
1988  * @max_effects: maximum number of effects supported by device
1989  * @effects: pointer to an array of effects currently loaded into device
1990  * @effect_owners: array of effect owners; when file handle owning
1991  *    an effect gets closed the effect is automatically erased
1992  *
1993  * Every force-feedback device must implement upload() and playback()
1994  * methods; erase() is optional. set_gain() and set_autocenter() need
1995  * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER
1996  * bits.
1997  *
1998  * Note that playback(), set_gain() and set_autocenter() are called with
1999  * dev->event_lock spinlock held and interrupts off and thus may not
2000  * sleep.
2001  */
2002 struct ff_device {
2003     int (*upload)(struct input_dev *dev, struct ff_effect *effect,
2004               struct ff_effect *old);
2005     int (*erase)(struct input_dev *dev, int effect_id);
2006 
2007     int (*playback)(struct input_dev *dev, int effect_id, int value);
2008     void (*set_gain)(struct input_dev *dev, u16 gain);
2009     void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
2010 
2011     void (*destroy)(struct ff_device *);
2012 
2013     void *private;
2014 
2015     unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
2016 
2017     struct mutex mutex;
2018 
2019     int max_effects;
2020     struct ff_effect *effects;
2021     struct file *effect_owners[];
2022 };
2023 
2024 int input_ff_create(struct input_dev *dev, int max_effects);
2025 void input_ff_destroy(struct input_dev *dev);
2026 
2027 int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
2028 
2029 int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
2030 int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
2031 
2032 int input_ff_create_memless(struct input_dev *dev, void *data,
2033         int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
2034 
2035 #endif
2036 #endif
2037 
2038  #define KEY_BACK 158 /* AC Back */
2039 
2040            KEY   CODE
2041 
2042 这里的值跟上面的XX.kl文件对应
2043 
2044 fraemworks/base/core/java/android/view/KeyEvent.java
2045 
2046 /*
2047  * Copyright (C) 2006 The Android Open Source Project
2048  *
2049  * Licensed under the Apache License, Version 2.0 (the "License");
2050  * you may not use this file except in compliance with the License.
2051  * You may obtain a copy of the License at
2052  *
2053  *      http://www.apache.org/licenses/LICENSE-2.0
2054  *
2055  * Unless required by applicable law or agreed to in writing, software
2056  * distributed under the License is distributed on an "AS IS" BASIS,
2057  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2058  * See the License for the specific language governing permissions and
2059  * limitations under the License.
2060  */
2061 
2062 package android.view;
2063 
2064 import android.os.Parcel;
2065 import android.os.Parcelable;
2066 import android.text.method.MetaKeyKeyListener;
2067 import android.util.Log;
2068 import android.util.Slog;
2069 import android.util.SparseArray;
2070 import android.util.SparseIntArray;
2071 import android.view.KeyCharacterMap;
2072 import android.view.KeyCharacterMap.KeyData;
2073 
2074 /**
2075  * Object used to report key and button events.
2076  * <p>
2077  * Each key press is described by a sequence of key events.  A key press
2078  * starts with a key event with {@link #ACTION_DOWN}.  If the key is held
2079  * sufficiently long that it repeats, then the initial down is followed
2080  * additional key events with {@link #ACTION_DOWN} and a non-zero value for
2081  * {@link #getRepeatCount()}.  The last key event is a {@link #ACTION_UP}
2082  * for the key up.  If the key press is canceled, the key up event will have the
2083  * {@link #FLAG_CANCELED} flag set.
2084  * </p><p>
2085  * Key events are generally accompanied by a key code ({@link #getKeyCode()}),
2086  * scan code ({@link #getScanCode()}) and meta state ({@link #getMetaState()}).
2087  * Key code constants are defined in this class.  Scan code constants are raw
2088  * device-specific codes obtained from the OS and so are not generally meaningful
2089  * to applications unless interpreted using the {@link KeyCharacterMap}.
2090  * Meta states describe the pressed state of key modifiers
2091  * such as {@link #META_SHIFT_ON} or {@link #META_ALT_ON}.
2092  * </p><p>
2093  * Key codes typically correspond one-to-one with individual keys on an input device.
2094  * Many keys and key combinations serve quite different functions on different
2095  * input devices so care must be taken when interpreting them.  Always use the
2096  * {@link KeyCharacterMap} associated with the input device when mapping keys
2097  * to characters.  Be aware that there may be multiple key input devices active
2098  * at the same time and each will have its own key character map.
2099  * </p><p>
2100  * As soft input methods can use multiple and inventive ways of inputting text,
2101  * there is no guarantee that any key press on a soft keyboard will generate a key
2102  * event: this is left to the IME's discretion, and in fact sending such events is
2103  * discouraged.  You should never rely on receiving KeyEvents for any key on a soft
2104  * input method.  In particular, the default software keyboard will never send any
2105  * key event to any application targetting Jelly Bean or later, and will only send
2106  * events for some presses of the delete and return keys to applications targetting
2107  * Ice Cream Sandwich or earlier.  Be aware that other software input methods may
2108  * never send key events regardless of the version.  Consider using editor actions
2109  * like {@link android.view.inputmethod.EditorInfo#IME_ACTION_DONE} if you need
2110  * specific interaction with the software keyboard, as it gives more visibility to
2111  * the user as to how your application will react to key presses.
2112  * </p><p>
2113  * When interacting with an IME, the framework may deliver key events
2114  * with the special action {@link #ACTION_MULTIPLE} that either specifies
2115  * that single repeated key code or a sequence of characters to insert.
2116  * </p><p>
2117  * In general, the framework cannot guarantee that the key events it delivers
2118  * to a view always constitute complete key sequences since some events may be dropped
2119  * or modified by containing views before they are delivered.  The view implementation
2120  * should be prepared to handle {@link #FLAG_CANCELED} and should tolerate anomalous
2121  * situations such as receiving a new {@link #ACTION_DOWN} without first having
2122  * received an {@link #ACTION_UP} for the prior key press.
2123  * </p><p>
2124  * Refer to {@link InputDevice} for more information about how different kinds of
2125  * input devices and sources represent keys and buttons.
2126  * </p>
2127  */
2128 public class KeyEvent extends InputEvent implements Parcelable {
2129     /** Key code constant: Unknown key code. */
2130     public static final int KEYCODE_UNKNOWN         = 0;
2131     /** Key code constant: Soft Left key.
2132      * Usually situated below the display on phones and used as a multi-function
2133      * feature key for selecting a software defined function shown on the bottom left
2134      * of the display. */
2135     public static final int KEYCODE_SOFT_LEFT       = 1;
2136     /** Key code constant: Soft Right key.
2137      * Usually situated below the display on phones and used as a multi-function
2138      * feature key for selecting a software defined function shown on the bottom right
2139      * of the display. */
2140     public static final int KEYCODE_SOFT_RIGHT      = 2;
2141     /** Key code constant: Home key.
2142      * This key is handled by the framework and is never delivered to applications. */
2143     public static final int KEYCODE_HOME            = 3;
2144     /** Key code constant: Back key. */
2145     public static final int KEYCODE_BACK            = 4;
2146     /** Key code constant: Call key. */
2147     public static final int KEYCODE_CALL            = 5;
2148     /** Key code constant: End Call key. */
2149     public static final int KEYCODE_ENDCALL         = 6;
2150     /** Key code constant: '0' key. */
2151     public static final int KEYCODE_0               = 7;
2152     /** Key code constant: '1' key. */
2153     public static final int KEYCODE_1               = 8;
2154     /** Key code constant: '2' key. */
2155     public static final int KEYCODE_2               = 9;
2156     /** Key code constant: '3' key. */
2157     public static final int KEYCODE_3               = 10;
2158     /** Key code constant: '4' key. */
2159     public static final int KEYCODE_4               = 11;
2160     /** Key code constant: '5' key. */
2161     public static final int KEYCODE_5               = 12;
2162     /** Key code constant: '6' key. */
2163     public static final int KEYCODE_6               = 13;
2164     /** Key code constant: '7' key. */
2165     public static final int KEYCODE_7               = 14;
2166     /** Key code constant: '8' key. */
2167     public static final int KEYCODE_8               = 15;
2168     /** Key code constant: '9' key. */
2169     public static final int KEYCODE_9               = 16;
2170     /** Key code constant: '*' key. */
2171     public static final int KEYCODE_STAR            = 17;
2172     /** Key code constant: '#' key. */
2173     public static final int KEYCODE_POUND           = 18;
2174     /** Key code constant: Directional Pad Up key.
2175      * May also be synthesized from trackball motions. */
2176     public static final int KEYCODE_DPAD_UP         = 19;
2177     /** Key code constant: Directional Pad Down key.
2178      * May also be synthesized from trackball motions. */
2179     public static final int KEYCODE_DPAD_DOWN       = 20;
2180     /** Key code constant: Directional Pad Left key.
2181      * May also be synthesized from trackball motions. */
2182     public static final int KEYCODE_DPAD_LEFT       = 21;
2183     /** Key code constant: Directional Pad Right key.
2184      * May also be synthesized from trackball motions. */
2185     public static final int KEYCODE_DPAD_RIGHT      = 22;
2186     /** Key code constant: Directional Pad Center key.
2187      * May also be synthesized from trackball motions. */
2188     public static final int KEYCODE_DPAD_CENTER     = 23;
2189     /** Key code constant: Volume Up key.
2190      * Adjusts the speaker volume up. */
2191     public static final int KEYCODE_VOLUME_UP       = 24;
2192     /** Key code constant: Volume Down key.
2193      * Adjusts the speaker volume down. */
2194     public static final int KEYCODE_VOLUME_DOWN     = 25;
2195     /** Key code constant: Power key. */
2196     public static final int KEYCODE_POWER           = 26;
2197     /** Key code constant: Camera key.
2198      * Used to launch a camera application or take pictures. */
2199     public static final int KEYCODE_CAMERA          = 27;
2200     /** Key code constant: Clear key. */
2201     public static final int KEYCODE_CLEAR           = 28;
2202     /** Key code constant: 'A' key. */
2203     public static final int KEYCODE_A               = 29;
2204     /** Key code constant: 'B' key. */
2205     public static final int KEYCODE_B               = 30;
2206     /** Key code constant: 'C' key. */
2207     public static final int KEYCODE_C               = 31;
2208     /** Key code constant: 'D' key. */
2209     public static final int KEYCODE_D               = 32;
2210     /** Key code constant: 'E' key. */
2211     public static final int KEYCODE_E               = 33;
2212     /** Key code constant: 'F' key. */
2213     public static final int KEYCODE_F               = 34;
2214     /** Key code constant: 'G' key. */
2215     public static final int KEYCODE_G               = 35;
2216     /** Key code constant: 'H' key. */
2217     public static final int KEYCODE_H               = 36;
2218     /** Key code constant: 'I' key. */
2219     public static final int KEYCODE_I               = 37;
2220     /** Key code constant: 'J' key. */
2221     public static final int KEYCODE_J               = 38;
2222     /** Key code constant: 'K' key. */
2223     public static final int KEYCODE_K               = 39;
2224     /** Key code constant: 'L' key. */
2225     public static final int KEYCODE_L               = 40;
2226     /** Key code constant: 'M' key. */
2227     public static final int KEYCODE_M               = 41;
2228     /** Key code constant: 'N' key. */
2229     public static final int KEYCODE_N               = 42;
2230     /** Key code constant: 'O' key. */
2231     public static final int KEYCODE_O               = 43;
2232     /** Key code constant: 'P' key. */
2233     public static final int KEYCODE_P               = 44;
2234     /** Key code constant: 'Q' key. */
2235     public static final int KEYCODE_Q               = 45;
2236     /** Key code constant: 'R' key. */
2237     public static final int KEYCODE_R               = 46;
2238     /** Key code constant: 'S' key. */
2239     public static final int KEYCODE_S               = 47;
2240     /** Key code constant: 'T' key. */
2241     public static final int KEYCODE_T               = 48;
2242     /** Key code constant: 'U' key. */
2243     public static final int KEYCODE_U               = 49;
2244     /** Key code constant: 'V' key. */
2245     public static final int KEYCODE_V               = 50;
2246     /** Key code constant: 'W' key. */
2247     public static final int KEYCODE_W               = 51;
2248     /** Key code constant: 'X' key. */
2249     public static final int KEYCODE_X               = 52;
2250     /** Key code constant: 'Y' key. */
2251     public static final int KEYCODE_Y               = 53;
2252     /** Key code constant: 'Z' key. */
2253     public static final int KEYCODE_Z               = 54;
2254     /** Key code constant: ',' key. */
2255     public static final int KEYCODE_COMMA           = 55;
2256     /** Key code constant: '.' key. */
2257     public static final int KEYCODE_PERIOD          = 56;
2258     /** Key code constant: Left Alt modifier key. */
2259     public static final int KEYCODE_ALT_LEFT        = 57;
2260     /** Key code constant: Right Alt modifier key. */
2261     public static final int KEYCODE_ALT_RIGHT       = 58;
2262     /** Key code constant: Left Shift modifier key. */
2263     public static final int KEYCODE_SHIFT_LEFT      = 59;
2264     /** Key code constant: Right Shift modifier key. */
2265     public static final int KEYCODE_SHIFT_RIGHT     = 60;
2266     /** Key code constant: Tab key. */
2267     public static final int KEYCODE_TAB             = 61;
2268     /** Key code constant: Space key. */
2269     public static final int KEYCODE_SPACE           = 62;
2270     /** Key code constant: Symbol modifier key.
2271      * Used to enter alternate symbols. */
2272     public static final int KEYCODE_SYM             = 63;
2273     /** Key code constant: Explorer special function key.
2274      * Used to launch a browser application. */
2275     public static final int KEYCODE_EXPLORER        = 64;
2276     /** Key code constant: Envelope special function key.
2277      * Used to launch a mail application. */
2278     public static final int KEYCODE_ENVELOPE        = 65;
2279     /** Key code constant: Enter key. */
2280     public static final int KEYCODE_ENTER           = 66;
2281     /** Key code constant: Backspace key.
2282      * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */
2283     public static final int KEYCODE_DEL             = 67;
2284     /** Key code constant: '`' (backtick) key. */
2285     public static final int KEYCODE_GRAVE           = 68;
2286     /** Key code constant: '-'. */
2287     public static final int KEYCODE_MINUS           = 69;
2288     /** Key code constant: '=' key. */
2289     public static final int KEYCODE_EQUALS          = 70;
2290     /** Key code constant: '[' key. */
2291     public static final int KEYCODE_LEFT_BRACKET    = 71;
2292     /** Key code constant: ']' key. */
2293     public static final int KEYCODE_RIGHT_BRACKET   = 72;
2294     /** Key code constant: '\' key. */
2295     public static final int KEYCODE_BACKSLASH       = 73;
2296     /** Key code constant: ';' key. */
2297     public static final int KEYCODE_SEMICOLON       = 74;
2298     /** Key code constant: ''' (apostrophe) key. */
2299     public static final int KEYCODE_APOSTROPHE      = 75;
2300     /** Key code constant: '/' key. */
2301     public static final int KEYCODE_SLASH           = 76;
2302     /** Key code constant: '@' key. */
2303     public static final int KEYCODE_AT              = 77;
2304     /** Key code constant: Number modifier key.
2305      * Used to enter numeric symbols.
2306      * This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is
2307      * interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */
2308     public static final int KEYCODE_NUM             = 78;
2309     /** Key code constant: Headset Hook key.
2310      * Used to hang up calls and stop media. */
2311     public static final int KEYCODE_HEADSETHOOK     = 79;
2312     /** Key code constant: Camera Focus key.
2313      * Used to focus the camera. */
2314     public static final int KEYCODE_FOCUS           = 80;   // *Camera* focus
2315     /** Key code constant: '+' key. */
2316     public static final int KEYCODE_PLUS            = 81;
2317     /** Key code constant: Menu key. */
2318     public static final int KEYCODE_MENU            = 82;
2319     /** Key code constant: Notification key. */
2320     public static final int KEYCODE_NOTIFICATION    = 83;
2321     /** Key code constant: Search key. */
2322     public static final int KEYCODE_SEARCH          = 84;
2323     /** Key code constant: Play/Pause media key. */
2324     public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85;
2325     /** Key code constant: Stop media key. */
2326     public static final int KEYCODE_MEDIA_STOP      = 86;
2327     /** Key code constant: Play Next media key. */
2328     public static final int KEYCODE_MEDIA_NEXT      = 87;
2329     /** Key code constant: Play Previous media key. */
2330     public static final int KEYCODE_MEDIA_PREVIOUS  = 88;
2331     /** Key code constant: Rewind media key. */
2332     public static final int KEYCODE_MEDIA_REWIND    = 89;
2333     /** Key code constant: Fast Forward media key. */
2334     public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;
2335     /** Key code constant: Mute key.
2336      * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */
2337     public static final int KEYCODE_MUTE            = 91;
2338     /** Key code constant: Page Up key. */
2339     public static final int KEYCODE_PAGE_UP         = 92;
2340     /** Key code constant: Page Down key. */
2341     public static final int KEYCODE_PAGE_DOWN       = 93;
2342     /** Key code constant: Picture Symbols modifier key.
2343      * Used to switch symbol sets (Emoji, Kao-moji). */
2344     public static final int KEYCODE_PICTSYMBOLS     = 94;   // switch symbol-sets (Emoji,Kao-moji)
2345     /** Key code constant: Switch Charset modifier key.
2346      * Used to switch character sets (Kanji, Katakana). */
2347     public static final int KEYCODE_SWITCH_CHARSET  = 95;   // switch char-sets (Kanji,Katakana)
2348     /** Key code constant: A Button key.
2349      * On a game controller, the A button should be either the button labeled A
2350      * or the first button on the upper row of controller buttons. */
2351     public static final int KEYCODE_BUTTON_A        = 96;
2352     /** Key code constant: B Button key.
2353      * On a game controller, the B button should be either the button labeled B
2354      * or the second button on the upper row of controller buttons. */
2355     public static final int KEYCODE_BUTTON_B        = 97;
2356     /** Key code constant: C Button key.
2357      * On a game controller, the C button should be either the button labeled C
2358      * or the third button on the upper row of controller buttons. */
2359     public static final int KEYCODE_BUTTON_C        = 98;
2360     /** Key code constant: X Button key.
2361      * On a game controller, the X button should be either the button labeled X
2362      * or the first button on the lower row of controller buttons. */
2363     public static final int KEYCODE_BUTTON_X        = 99;
2364     /** Key code constant: Y Button key.
2365      * On a game controller, the Y button should be either the button labeled Y
2366      * or the second button on the lower row of controller buttons. */
2367     public static final int KEYCODE_BUTTON_Y        = 100;
2368     /** Key code constant: Z Button key.
2369      * On a game controller, the Z button should be either the button labeled Z
2370      * or the third button on the lower row of controller buttons. */
2371     public static final int KEYCODE_BUTTON_Z        = 101;
2372     /** Key code constant: L1 Button key.
2373      * On a game controller, the L1 button should be either the button labeled L1 (or L)
2374      * or the top left trigger button. */
2375     public static final int KEYCODE_BUTTON_L1       = 102;
2376     /** Key code constant: R1 Button key.
2377      * On a game controller, the R1 button should be either the button labeled R1 (or R)
2378      * or the top right trigger button. */
2379     public static final int KEYCODE_BUTTON_R1       = 103;
2380     /** Key code constant: L2 Button key.
2381      * On a game controller, the L2 button should be either the button labeled L2
2382      * or the bottom left trigger button. */
2383     public static final int KEYCODE_BUTTON_L2       = 104;
2384     /** Key code constant: R2 Button key.
2385      * On a game controller, the R2 button should be either the button labeled R2
2386      * or the bottom right trigger button. */
2387     public static final int KEYCODE_BUTTON_R2       = 105;
2388     /** Key code constant: Left Thumb Button key.
2389      * On a game controller, the left thumb button indicates that the left (or only)
2390      * joystick is pressed. */
2391     public static final int KEYCODE_BUTTON_THUMBL   = 106;
2392     /** Key code constant: Right Thumb Button key.
2393      * On a game controller, the right thumb button indicates that the right
2394      * joystick is pressed. */
2395     public static final int KEYCODE_BUTTON_THUMBR   = 107;
2396     /** Key code constant: Start Button key.
2397      * On a game controller, the button labeled Start. */
2398     public static final int KEYCODE_BUTTON_START    = 108;
2399     /** Key code constant: Select Button key.
2400      * On a game controller, the button labeled Select. */
2401     public static final int KEYCODE_BUTTON_SELECT   = 109;
2402     /** Key code constant: Mode Button key.
2403      * On a game controller, the button labeled Mode. */
2404     public static final int KEYCODE_BUTTON_MODE     = 110;
2405     /** Key code constant: Escape key. */
2406     public static final int KEYCODE_ESCAPE          = 111;
2407     /** Key code constant: Forward Delete key.
2408      * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */
2409     public static final int KEYCODE_FORWARD_DEL     = 112;
2410     /** Key code constant: Left Control modifier key. */
2411     public static final int KEYCODE_CTRL_LEFT       = 113;
2412     /** Key code constant: Right Control modifier key. */
2413     public static final int KEYCODE_CTRL_RIGHT      = 114;
2414     /** Key code constant: Caps Lock key. */
2415     public static final int KEYCODE_CAPS_LOCK       = 115;
2416     /** Key code constant: Scroll Lock key. */
2417     public static final int KEYCODE_SCROLL_LOCK     = 116;
2418     /** Key code constant: Left Meta modifier key. */
2419     public static final int KEYCODE_META_LEFT       = 117;
2420     /** Key code constant: Right Meta modifier key. */
2421     public static final int KEYCODE_META_RIGHT      = 118;
2422     /** Key code constant: Function modifier key. */
2423     public static final int KEYCODE_FUNCTION        = 119;
2424     /** Key code constant: System Request / Print Screen key. */
2425     public static final int KEYCODE_SYSRQ           = 120;
2426     /** Key code constant: Break / Pause key. */
2427     public static final int KEYCODE_BREAK           = 121;
2428     /** Key code constant: Home Movement key.
2429      * Used for scrolling or moving the cursor around to the start of a line
2430      * or to the top of a list. */
2431     public static final int KEYCODE_MOVE_HOME       = 122;
2432     /** Key code constant: End Movement key.
2433      * Used for scrolling or moving the cursor around to the end of a line
2434      * or to the bottom of a list. */
2435     public static final int KEYCODE_MOVE_END        = 123;
2436     /** Key code constant: Insert key.
2437      * Toggles insert / overwrite edit mode. */
2438     public static final int KEYCODE_INSERT          = 124;
2439     /** Key code constant: Forward key.
2440      * Navigates forward in the history stack.  Complement of {@link #KEYCODE_BACK}. */
2441     public static final int KEYCODE_FORWARD         = 125;
2442     /** Key code constant: Play media key. */
2443     public static final int KEYCODE_MEDIA_PLAY      = 126;
2444     /** Key code constant: Pause media key. */
2445     public static final int KEYCODE_MEDIA_PAUSE     = 127;
2446     /** Key code constant: Close media key.
2447      * May be used to close a CD tray, for example. */
2448     public static final int KEYCODE_MEDIA_CLOSE     = 128;
2449     /** Key code constant: Eject media key.
2450      * May be used to eject a CD tray, for example. */
2451     public static final int KEYCODE_MEDIA_EJECT     = 129;
2452     /** Key code constant: Record media key. */
2453     public static final int KEYCODE_MEDIA_RECORD    = 130;
2454     /** Key code constant: F1 key. */
2455     public static final int KEYCODE_F1              = 131;
2456     /** Key code constant: F2 key. */
2457     public static final int KEYCODE_F2              = 132;
2458     /** Key code constant: F3 key. */
2459     public static final int KEYCODE_F3              = 133;
2460     /** Key code constant: F4 key. */
2461     public static final int KEYCODE_F4              = 134;
2462     /** Key code constant: F5 key. */
2463     public static final int KEYCODE_F5              = 135;
2464     /** Key code constant: F6 key. */
2465     public static final int KEYCODE_F6              = 136;
2466     /** Key code constant: F7 key. */
2467     public static final int KEYCODE_F7              = 137;
2468     /** Key code constant: F8 key. */
2469     public static final int KEYCODE_F8              = 138;
2470     /** Key code constant: F9 key. */
2471     public static final int KEYCODE_F9              = 139;
2472     /** Key code constant: F10 key. */
2473     public static final int KEYCODE_F10             = 140;
2474     /** Key code constant: F11 key. */
2475     public static final int KEYCODE_F11             = 141;
2476     /** Key code constant: F12 key. */
2477     public static final int KEYCODE_F12             = 142;
2478     /** Key code constant: Num Lock key.
2479      * This is the Num Lock key; it is different from {@link #KEYCODE_NUM}.
2480      * This key alters the behavior of other keys on the numeric keypad. */
2481     public static final int KEYCODE_NUM_LOCK        = 143;
2482     /** Key code constant: Numeric keypad '0' key. */
2483     public static final int KEYCODE_NUMPAD_0        = 144;
2484     /** Key code constant: Numeric keypad '1' key. */
2485     public static final int KEYCODE_NUMPAD_1        = 145;
2486     /** Key code constant: Numeric keypad '2' key. */
2487     public static final int KEYCODE_NUMPAD_2        = 146;
2488     /** Key code constant: Numeric keypad '3' key. */
2489     public static final int KEYCODE_NUMPAD_3        = 147;
2490     /** Key code constant: Numeric keypad '4' key. */
2491     public static final int KEYCODE_NUMPAD_4        = 148;
2492     /** Key code constant: Numeric keypad '5' key. */
2493     public static final int KEYCODE_NUMPAD_5        = 149;
2494     /** Key code constant: Numeric keypad '6' key. */
2495     public static final int KEYCODE_NUMPAD_6        = 150;
2496     /** Key code constant: Numeric keypad '7' key. */
2497     public static final int KEYCODE_NUMPAD_7        = 151;
2498     /** Key code constant: Numeric keypad '8' key. */
2499     public static final int KEYCODE_NUMPAD_8        = 152;
2500     /** Key code constant: Numeric keypad '9' key. */
2501     public static final int KEYCODE_NUMPAD_9        = 153;
2502     /** Key code constant: Numeric keypad '/' key (for division). */
2503     public static final int KEYCODE_NUMPAD_DIVIDE   = 154;
2504     /** Key code constant: Numeric keypad '*' key (for multiplication). */
2505     public static final int KEYCODE_NUMPAD_MULTIPLY = 155;
2506     /** Key code constant: Numeric keypad '-' key (for subtraction). */
2507     public static final int KEYCODE_NUMPAD_SUBTRACT = 156;
2508     /** Key code constant: Numeric keypad '+' key (for addition). */
2509     public static final int KEYCODE_NUMPAD_ADD      = 157;
2510     /** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */
2511     public static final int KEYCODE_NUMPAD_DOT      = 158;
2512     /** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */
2513     public static final int KEYCODE_NUMPAD_COMMA    = 159;
2514     /** Key code constant: Numeric keypad Enter key. */
2515     public static final int KEYCODE_NUMPAD_ENTER    = 160;
2516     /** Key code constant: Numeric keypad '=' key. */
2517     public static final int KEYCODE_NUMPAD_EQUALS   = 161;
2518     /** Key code constant: Numeric keypad '(' key. */
2519     public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162;
2520     /** Key code constant: Numeric keypad ')' key. */
2521     public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163;
2522     /** Key code constant: Volume Mute key.
2523      * Mutes the speaker, unlike {@link #KEYCODE_MUTE}.
2524      * This key should normally be implemented as a toggle such that the first press
2525      * mutes the speaker and the second press restores the original volume. */
2526     public static final int KEYCODE_VOLUME_MUTE     = 164;
2527     /** Key code constant: Info key.
2528      * Common on TV remotes to show additional information related to what is
2529      * currently being viewed. */
2530     public static final int KEYCODE_INFO            = 165;
2531     /** Key code constant: Channel up key.
2532      * On TV remotes, increments the television channel. */
2533     public static final int KEYCODE_CHANNEL_UP      = 166;
2534     /** Key code constant: Channel down key.
2535      * On TV remotes, decrements the television channel. */
2536     public static final int KEYCODE_CHANNEL_DOWN    = 167;
2537     /** Key code constant: Zoom in key. */
2538     public static final int KEYCODE_ZOOM_IN         = 168;
2539     /** Key code constant: Zoom out key. */
2540     public static final int KEYCODE_ZOOM_OUT        = 169;
2541     /** Key code constant: TV key.
2542      * On TV remotes, switches to viewing live TV. */
2543     public static final int KEYCODE_TV              = 170;
2544     /** Key code constant: Window key.
2545      * On TV remotes, toggles picture-in-picture mode or other windowing functions. */
2546     public static final int KEYCODE_WINDOW          = 171;
2547     /** Key code constant: Guide key.
2548      * On TV remotes, shows a programming guide. */
2549     public static final int KEYCODE_GUIDE           = 172;
2550     /** Key code constant: DVR key.
2551      * On some TV remotes, switches to a DVR mode for recorded shows. */
2552     public static final int KEYCODE_DVR             = 173;
2553     /** Key code constant: Bookmark key.
2554      * On some TV remotes, bookmarks content or web pages. */
2555     public static final int KEYCODE_BOOKMARK        = 174;
2556     /** Key code constant: Toggle captions key.
2557      * Switches the mode for closed-captioning text, for example during television shows. */
2558     public static final int KEYCODE_CAPTIONS        = 175;
2559     /** Key code constant: Settings key.
2560      * Starts the system settings activity. */
2561     public static final int KEYCODE_SETTINGS        = 176;
2562     /** Key code constant: TV power key.
2563      * On TV remotes, toggles the power on a television screen. */
2564     public static final int KEYCODE_TV_POWER        = 177;
2565     /** Key code constant: TV input key.
2566      * On TV remotes, switches the input on a television screen. */
2567     public static final int KEYCODE_TV_INPUT        = 178;
2568     /** Key code constant: Set-top-box power key.
2569      * On TV remotes, toggles the power on an external Set-top-box. */
2570     public static final int KEYCODE_STB_POWER       = 179;
2571     /** Key code constant: Set-top-box input key.
2572      * On TV remotes, switches the input mode on an external Set-top-box. */
2573     public static final int KEYCODE_STB_INPUT       = 180;
2574     /** Key code constant: A/V Receiver power key.
2575      * On TV remotes, toggles the power on an external A/V Receiver. */
2576     public static final int KEYCODE_AVR_POWER       = 181;
2577     /** Key code constant: A/V Receiver input key.
2578      * On TV remotes, switches the input mode on an external A/V Receiver. */
2579     public static final int KEYCODE_AVR_INPUT       = 182;
2580     /** Key code constant: Red "programmable" key.
2581      * On TV remotes, acts as a contextual/programmable key. */
2582     public static final int KEYCODE_PROG_RED        = 183;
2583     /** Key code constant: Green "programmable" key.
2584      * On TV remotes, actsas a contextual/programmable key. */
2585     public static final int KEYCODE_PROG_GREEN      = 184;
2586     /** Key code constant: Yellow "programmable" key.
2587      * On TV remotes, acts as a contextual/programmable key. */
2588     public static final int KEYCODE_PROG_YELLOW     = 185;
2589     /** Key code constant: Blue "programmable" key.
2590      * On TV remotes, acts as a contextual/programmable key. */
2591     public static final int KEYCODE_PROG_BLUE       = 186;
2592     /** Key code constant: App switch key.
2593      * Should bring up the application switcher dialog. */
2594     public static final int KEYCODE_APP_SWITCH      = 187;
2595     /** Key code constant: Generic Game Pad Button #1.*/
2596     public static final int KEYCODE_BUTTON_1        = 188;
2597     /** Key code constant: Generic Game Pad Button #2.*/
2598     public static final int KEYCODE_BUTTON_2        = 189;
2599     /** Key code constant: Generic Game Pad Button #3.*/
2600     public static final int KEYCODE_BUTTON_3        = 190;
2601     /** Key code constant: Generic Game Pad Button #4.*/
2602     public static final int KEYCODE_BUTTON_4        = 191;
2603     /** Key code constant: Generic Game Pad Button #5.*/
2604     public static final int KEYCODE_BUTTON_5        = 192;
2605     /** Key code constant: Generic Game Pad Button #6.*/
2606     public static final int KEYCODE_BUTTON_6        = 193;
2607     /** Key code constant: Generic Game Pad Button #7.*/
2608     public static final int KEYCODE_BUTTON_7        = 194;
2609     /** Key code constant: Generic Game Pad Button #8.*/
2610     public static final int KEYCODE_BUTTON_8        = 195;
2611     /** Key code constant: Generic Game Pad Button #9.*/
2612     public static final int KEYCODE_BUTTON_9        = 196;
2613     /** Key code constant: Generic Game Pad Button #10.*/
2614     public static final int KEYCODE_BUTTON_10       = 197;
2615     /** Key code constant: Generic Game Pad Button #11.*/
2616     public static final int KEYCODE_BUTTON_11       = 198;
2617     /** Key code constant: Generic Game Pad Button #12.*/
2618     public static final int KEYCODE_BUTTON_12       = 199;
2619     /** Key code constant: Generic Game Pad Button #13.*/
2620     public static final int KEYCODE_BUTTON_13       = 200;
2621     /** Key code constant: Generic Game Pad Button #14.*/
2622     public static final int KEYCODE_BUTTON_14       = 201;
2623     /** Key code constant: Generic Game Pad Button #15.*/
2624     public static final int KEYCODE_BUTTON_15       = 202;
2625     /** Key code constant: Generic Game Pad Button #16.*/
2626     public static final int KEYCODE_BUTTON_16       = 203;
2627     /** Key code constant: Language Switch key.
2628      * Toggles the current input language such as switching between English and Japanese on
2629      * a QWERTY keyboard.  On some devices, the same function may be performed by
2630      * pressing Shift+Spacebar. */
2631     public static final int KEYCODE_LANGUAGE_SWITCH = 204;
2632     /** Key code constant: Manner Mode key.
2633      * Toggles silent or vibrate mode on and off to make the device behave more politely
2634      * in certain settings such as on a crowded train.  On some devices, the key may only
2635      * operate when long-pressed. */
2636     public static final int KEYCODE_MANNER_MODE     = 205;
2637     /** Key code constant: 3D Mode key.
2638      * Toggles the display between 2D and 3D mode. */
2639     public static final int KEYCODE_3D_MODE         = 206;
2640     /** Key code constant: Contacts special function key.
2641      * Used to launch an address book application. */
2642     public static final int KEYCODE_CONTACTS        = 207;
2643     /** Key code constant: Calendar special function key.
2644      * Used to launch a calendar application. */
2645     public static final int KEYCODE_CALENDAR        = 208;
2646     /** Key code constant: Music special function key.
2647      * Used to launch a music player application. */
2648     public static final int KEYCODE_MUSIC           = 209;
2649     /** Key code constant: Calculator special function key.
2650      * Used to launch a calculator application. */
2651     public static final int KEYCODE_CALCULATOR      = 210;
2652     /** Key code constant: Japanese full-width / half-width key. */
2653     public static final int KEYCODE_ZENKAKU_HANKAKU = 211;
2654     /** Key code constant: Japanese alphanumeric key. */
2655     public static final int KEYCODE_EISU            = 212;
2656     /** Key code constant: Japanese non-conversion key. */
2657     public static final int KEYCODE_MUHENKAN        = 213;
2658     /** Key code constant: Japanese conversion key. */
2659     public static final int KEYCODE_HENKAN          = 214;
2660     /** Key code constant: Japanese katakana / hiragana key. */
2661     public static final int KEYCODE_KATAKANA_HIRAGANA = 215;
2662     /** Key code constant: Japanese Yen key. */
2663     public static final int KEYCODE_YEN             = 216;
2664     /** Key code constant: Japanese Ro key. */
2665     public static final int KEYCODE_RO              = 217;
2666     /** Key code constant: Japanese kana key. */
2667     public static final int KEYCODE_KANA            = 218;
2668     /** Key code constant: Assist key.
2669      * Launches the global assist activity.  Not delivered to applications. */
2670     public static final int KEYCODE_ASSIST          = 219;
2671 
2672     private static final int LAST_KEYCODE           = KEYCODE_ASSIST;
2673 
2674     // NOTE: If you add a new keycode here you must also add it to:
2675     //  isSystem()
2676     //  native/include/android/keycodes.h
2677     //  frameworks/base/include/ui/KeycodeLabels.h
2678     //  external/webkit/WebKit/android/plugins/ANPKeyCodes.h
2679     //  frameworks/base/core/res/res/values/attrs.xml
2680     //  emulator?
2681     //  LAST_KEYCODE
2682     //  KEYCODE_SYMBOLIC_NAMES
2683     //
2684     //  Also Android currently does not reserve code ranges for vendor-
2685     //  specific key codes.  If you have new key codes to have, you
2686     //  MUST contribute a patch to the open source project to define
2687     //  those new codes.  This is intended to maintain a consistent
2688     //  set of key code definitions across all Android devices.
2689 
2690     // Symbolic names of all key codes.
2691     private static final SparseArray<String> KEYCODE_SYMBOLIC_NAMES = new SparseArray<String>();
2692     private static void populateKeycodeSymbolicNames() {
2693         SparseArray<String> names = KEYCODE_SYMBOLIC_NAMES;
2694         names.append(KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN");
2695         names.append(KEYCODE_SOFT_LEFT, "KEYCODE_SOFT_LEFT");
2696         names.append(KEYCODE_SOFT_RIGHT, "KEYCODE_SOFT_RIGHT");
2697         names.append(KEYCODE_HOME, "KEYCODE_HOME");
2698         names.append(KEYCODE_BACK, "KEYCODE_BACK");
2699         names.append(KEYCODE_CALL, "KEYCODE_CALL");
2700         names.append(KEYCODE_ENDCALL, "KEYCODE_ENDCALL");
2701         names.append(KEYCODE_0, "KEYCODE_0");
2702         names.append(KEYCODE_1, "KEYCODE_1");
2703         names.append(KEYCODE_2, "KEYCODE_2");
2704         names.append(KEYCODE_3, "KEYCODE_3");
2705         names.append(KEYCODE_4, "KEYCODE_4");
2706         names.append(KEYCODE_5, "KEYCODE_5");
2707         names.append(KEYCODE_6, "KEYCODE_6");
2708         names.append(KEYCODE_7, "KEYCODE_7");
2709         names.append(KEYCODE_8, "KEYCODE_8");
2710         names.append(KEYCODE_9, "KEYCODE_9");
2711         names.append(KEYCODE_STAR, "KEYCODE_STAR");
2712         names.append(KEYCODE_POUND, "KEYCODE_POUND");
2713         names.append(KEYCODE_DPAD_UP, "KEYCODE_DPAD_UP");
2714         names.append(KEYCODE_DPAD_DOWN, "KEYCODE_DPAD_DOWN");
2715         names.append(KEYCODE_DPAD_LEFT, "KEYCODE_DPAD_LEFT");
2716         names.append(KEYCODE_DPAD_RIGHT, "KEYCODE_DPAD_RIGHT");
2717         names.append(KEYCODE_DPAD_CENTER, "KEYCODE_DPAD_CENTER");
2718         names.append(KEYCODE_VOLUME_UP, "KEYCODE_VOLUME_UP");
2719         names.append(KEYCODE_VOLUME_DOWN, "KEYCODE_VOLUME_DOWN");
2720         names.append(KEYCODE_POWER, "KEYCODE_POWER");
2721         names.append(KEYCODE_CAMERA, "KEYCODE_CAMERA");
2722         names.append(KEYCODE_CLEAR, "KEYCODE_CLEAR");
2723         names.append(KEYCODE_A, "KEYCODE_A");
2724         names.append(KEYCODE_B, "KEYCODE_B");
2725         names.append(KEYCODE_C, "KEYCODE_C");
2726         names.append(KEYCODE_D, "KEYCODE_D");
2727         names.append(KEYCODE_E, "KEYCODE_E");
2728         names.append(KEYCODE_F, "KEYCODE_F");
2729         names.append(KEYCODE_G, "KEYCODE_G");
2730         names.append(KEYCODE_H, "KEYCODE_H");
2731         names.append(KEYCODE_I, "KEYCODE_I");
2732         names.append(KEYCODE_J, "KEYCODE_J");
2733         names.append(KEYCODE_K, "KEYCODE_K");
2734         names.append(KEYCODE_L, "KEYCODE_L");
2735         names.append(KEYCODE_M, "KEYCODE_M");
2736         names.append(KEYCODE_N, "KEYCODE_N");
2737         names.append(KEYCODE_O, "KEYCODE_O");
2738         names.append(KEYCODE_P, "KEYCODE_P");
2739         names.append(KEYCODE_Q, "KEYCODE_Q");
2740         names.append(KEYCODE_R, "KEYCODE_R");
2741         names.append(KEYCODE_S, "KEYCODE_S");
2742         names.append(KEYCODE_T, "KEYCODE_T");
2743         names.append(KEYCODE_U, "KEYCODE_U");
2744         names.append(KEYCODE_V, "KEYCODE_V");
2745         names.append(KEYCODE_W, "KEYCODE_W");
2746         names.append(KEYCODE_X, "KEYCODE_X");
2747         names.append(KEYCODE_Y, "KEYCODE_Y");
2748         names.append(KEYCODE_Z, "KEYCODE_Z");
2749         names.append(KEYCODE_COMMA, "KEYCODE_COMMA");
2750         names.append(KEYCODE_PERIOD, "KEYCODE_PERIOD");
2751         names.append(KEYCODE_ALT_LEFT, "KEYCODE_ALT_LEFT");
2752         names.append(KEYCODE_ALT_RIGHT, "KEYCODE_ALT_RIGHT");
2753         names.append(KEYCODE_SHIFT_LEFT, "KEYCODE_SHIFT_LEFT");
2754         names.append(KEYCODE_SHIFT_RIGHT, "KEYCODE_SHIFT_RIGHT");
2755         names.append(KEYCODE_TAB, "KEYCODE_TAB");
2756         names.append(KEYCODE_SPACE, "KEYCODE_SPACE");
2757         names.append(KEYCODE_SYM, "KEYCODE_SYM");
2758         names.append(KEYCODE_EXPLORER, "KEYCODE_EXPLORER");
2759         names.append(KEYCODE_ENVELOPE, "KEYCODE_ENVELOPE");
2760         names.append(KEYCODE_ENTER, "KEYCODE_ENTER");
2761         names.append(KEYCODE_DEL, "KEYCODE_DEL");
2762         names.append(KEYCODE_GRAVE, "KEYCODE_GRAVE");
2763         names.append(KEYCODE_MINUS, "KEYCODE_MINUS");
2764         names.append(KEYCODE_EQUALS, "KEYCODE_EQUALS");
2765         names.append(KEYCODE_LEFT_BRACKET, "KEYCODE_LEFT_BRACKET");
2766         names.append(KEYCODE_RIGHT_BRACKET, "KEYCODE_RIGHT_BRACKET");
2767         names.append(KEYCODE_BACKSLASH, "KEYCODE_BACKSLASH");
2768         names.append(KEYCODE_SEMICOLON, "KEYCODE_SEMICOLON");
2769         names.append(KEYCODE_APOSTROPHE, "KEYCODE_APOSTROPHE");
2770         names.append(KEYCODE_SLASH, "KEYCODE_SLASH");
2771         names.append(KEYCODE_AT, "KEYCODE_AT");
2772         names.append(KEYCODE_NUM, "KEYCODE_NUM");
2773         names.append(KEYCODE_HEADSETHOOK, "KEYCODE_HEADSETHOOK");
2774         names.append(KEYCODE_FOCUS, "KEYCODE_FOCUS");
2775         names.append(KEYCODE_PLUS, "KEYCODE_PLUS");
2776         names.append(KEYCODE_MENU, "KEYCODE_MENU");
2777         names.append(KEYCODE_NOTIFICATION, "KEYCODE_NOTIFICATION");
2778         names.append(KEYCODE_SEARCH, "KEYCODE_SEARCH");
2779         names.append(KEYCODE_MEDIA_PLAY_PAUSE, "KEYCODE_MEDIA_PLAY_PAUSE");
2780         names.append(KEYCODE_MEDIA_STOP, "KEYCODE_MEDIA_STOP");
2781         names.append(KEYCODE_MEDIA_NEXT, "KEYCODE_MEDIA_NEXT");
2782         names.append(KEYCODE_MEDIA_PREVIOUS, "KEYCODE_MEDIA_PREVIOUS");
2783         names.append(KEYCODE_MEDIA_REWIND, "KEYCODE_MEDIA_REWIND");
2784         names.append(KEYCODE_MEDIA_FAST_FORWARD, "KEYCODE_MEDIA_FAST_FORWARD");
2785         names.append(KEYCODE_MUTE, "KEYCODE_MUTE");
2786         names.append(KEYCODE_PAGE_UP, "KEYCODE_PAGE_UP");
2787         names.append(KEYCODE_PAGE_DOWN, "KEYCODE_PAGE_DOWN");
2788         names.append(KEYCODE_PICTSYMBOLS, "KEYCODE_PICTSYMBOLS");
2789         names.append(KEYCODE_SWITCH_CHARSET, "KEYCODE_SWITCH_CHARSET");
2790         names.append(KEYCODE_BUTTON_A, "KEYCODE_BUTTON_A");
2791         names.append(KEYCODE_BUTTON_B, "KEYCODE_BUTTON_B");
2792         names.append(KEYCODE_BUTTON_C, "KEYCODE_BUTTON_C");
2793         names.append(KEYCODE_BUTTON_X, "KEYCODE_BUTTON_X");
2794         names.append(KEYCODE_BUTTON_Y, "KEYCODE_BUTTON_Y");
2795         names.append(KEYCODE_BUTTON_Z, "KEYCODE_BUTTON_Z");
2796         names.append(KEYCODE_BUTTON_L1, "KEYCODE_BUTTON_L1");
2797         names.append(KEYCODE_BUTTON_R1, "KEYCODE_BUTTON_R1");
2798         names.append(KEYCODE_BUTTON_L2, "KEYCODE_BUTTON_L2");
2799         names.append(KEYCODE_BUTTON_R2, "KEYCODE_BUTTON_R2");
2800         names.append(KEYCODE_BUTTON_THUMBL, "KEYCODE_BUTTON_THUMBL");
2801         names.append(KEYCODE_BUTTON_THUMBR, "KEYCODE_BUTTON_THUMBR");
2802         names.append(KEYCODE_BUTTON_START, "KEYCODE_BUTTON_START");
2803         names.append(KEYCODE_BUTTON_SELECT, "KEYCODE_BUTTON_SELECT");
2804         names.append(KEYCODE_BUTTON_MODE, "KEYCODE_BUTTON_MODE");
2805         names.append(KEYCODE_ESCAPE, "KEYCODE_ESCAPE");
2806         names.append(KEYCODE_FORWARD_DEL, "KEYCODE_FORWARD_DEL");
2807         names.append(KEYCODE_CTRL_LEFT, "KEYCODE_CTRL_LEFT");
2808         names.append(KEYCODE_CTRL_RIGHT, "KEYCODE_CTRL_RIGHT");
2809         names.append(KEYCODE_CAPS_LOCK, "KEYCODE_CAPS_LOCK");
2810         names.append(KEYCODE_SCROLL_LOCK, "KEYCODE_SCROLL_LOCK");
2811         names.append(KEYCODE_META_LEFT, "KEYCODE_META_LEFT");
2812         names.append(KEYCODE_META_RIGHT, "KEYCODE_META_RIGHT");
2813         names.append(KEYCODE_FUNCTION, "KEYCODE_FUNCTION");
2814         names.append(KEYCODE_SYSRQ, "KEYCODE_SYSRQ");
2815         names.append(KEYCODE_BREAK, "KEYCODE_BREAK");
2816         names.append(KEYCODE_MOVE_HOME, "KEYCODE_MOVE_HOME");
2817         names.append(KEYCODE_MOVE_END, "KEYCODE_MOVE_END");
2818         names.append(KEYCODE_INSERT, "KEYCODE_INSERT");
2819         names.append(KEYCODE_FORWARD, "KEYCODE_FORWARD");
2820         names.append(KEYCODE_MEDIA_PLAY, "KEYCODE_MEDIA_PLAY");
2821         names.append(KEYCODE_MEDIA_PAUSE, "KEYCODE_MEDIA_PAUSE");
2822         names.append(KEYCODE_MEDIA_CLOSE, "KEYCODE_MEDIA_CLOSE");
2823         names.append(KEYCODE_MEDIA_EJECT, "KEYCODE_MEDIA_EJECT");
2824         names.append(KEYCODE_MEDIA_RECORD, "KEYCODE_MEDIA_RECORD");
2825         names.append(KEYCODE_F1, "KEYCODE_F1");
2826         names.append(KEYCODE_F2, "KEYCODE_F2");
2827         names.append(KEYCODE_F3, "KEYCODE_F3");
2828         names.append(KEYCODE_F4, "KEYCODE_F4");
2829         names.append(KEYCODE_F5, "KEYCODE_F5");
2830         names.append(KEYCODE_F6, "KEYCODE_F6");
2831         names.append(KEYCODE_F7, "KEYCODE_F7");
2832         names.append(KEYCODE_F8, "KEYCODE_F8");
2833         names.append(KEYCODE_F9, "KEYCODE_F9");
2834         names.append(KEYCODE_F10, "KEYCODE_F10");
2835         names.append(KEYCODE_F11, "KEYCODE_F11");
2836         names.append(KEYCODE_F12, "KEYCODE_F12");
2837         names.append(KEYCODE_NUM_LOCK, "KEYCODE_NUM_LOCK");
2838         names.append(KEYCODE_NUMPAD_0, "KEYCODE_NUMPAD_0");
2839         names.append(KEYCODE_NUMPAD_1, "KEYCODE_NUMPAD_1");
2840         names.append(KEYCODE_NUMPAD_2, "KEYCODE_NUMPAD_2");
2841         names.append(KEYCODE_NUMPAD_3, "KEYCODE_NUMPAD_3");
2842         names.append(KEYCODE_NUMPAD_4, "KEYCODE_NUMPAD_4");
2843         names.append(KEYCODE_NUMPAD_5, "KEYCODE_NUMPAD_5");
2844         names.append(KEYCODE_NUMPAD_6, "KEYCODE_NUMPAD_6");
2845         names.append(KEYCODE_NUMPAD_7, "KEYCODE_NUMPAD_7");
2846         names.append(KEYCODE_NUMPAD_8, "KEYCODE_NUMPAD_8");
2847         names.append(KEYCODE_NUMPAD_9, "KEYCODE_NUMPAD_9");
2848         names.append(KEYCODE_NUMPAD_DIVIDE, "KEYCODE_NUMPAD_DIVIDE");
2849         names.append(KEYCODE_NUMPAD_MULTIPLY, "KEYCODE_NUMPAD_MULTIPLY");
2850         names.append(KEYCODE_NUMPAD_SUBTRACT, "KEYCODE_NUMPAD_SUBTRACT");
2851         names.append(KEYCODE_NUMPAD_ADD, "KEYCODE_NUMPAD_ADD");
2852         names.append(KEYCODE_NUMPAD_DOT, "KEYCODE_NUMPAD_DOT");
2853         names.append(KEYCODE_NUMPAD_COMMA, "KEYCODE_NUMPAD_COMMA");
2854         names.append(KEYCODE_NUMPAD_ENTER, "KEYCODE_NUMPAD_ENTER");
2855         names.append(KEYCODE_NUMPAD_EQUALS, "KEYCODE_NUMPAD_EQUALS");
2856         names.append(KEYCODE_NUMPAD_LEFT_PAREN, "KEYCODE_NUMPAD_LEFT_PAREN");
2857         names.append(KEYCODE_NUMPAD_RIGHT_PAREN, "KEYCODE_NUMPAD_RIGHT_PAREN");
2858         names.append(KEYCODE_VOLUME_MUTE, "KEYCODE_VOLUME_MUTE");
2859         names.append(KEYCODE_INFO, "KEYCODE_INFO");
2860         names.append(KEYCODE_CHANNEL_UP, "KEYCODE_CHANNEL_UP");
2861         names.append(KEYCODE_CHANNEL_DOWN, "KEYCODE_CHANNEL_DOWN");
2862         names.append(KEYCODE_ZOOM_IN, "KEYCODE_ZOOM_IN");
2863         names.append(KEYCODE_ZOOM_OUT, "KEYCODE_ZOOM_OUT");
2864         names.append(KEYCODE_TV, "KEYCODE_TV");
2865         names.append(KEYCODE_WINDOW, "KEYCODE_WINDOW");
2866         names.append(KEYCODE_GUIDE, "KEYCODE_GUIDE");
2867         names.append(KEYCODE_DVR, "KEYCODE_DVR");
2868         names.append(KEYCODE_BOOKMARK, "KEYCODE_BOOKMARK");
2869         names.append(KEYCODE_CAPTIONS, "KEYCODE_CAPTIONS");
2870         names.append(KEYCODE_SETTINGS, "KEYCODE_SETTINGS");
2871         names.append(KEYCODE_TV_POWER, "KEYCODE_TV_POWER");
2872         names.append(KEYCODE_TV_INPUT, "KEYCODE_TV_INPUT");
2873         names.append(KEYCODE_STB_INPUT, "KEYCODE_STB_INPUT");
2874         names.append(KEYCODE_STB_POWER, "KEYCODE_STB_POWER");
2875         names.append(KEYCODE_AVR_POWER, "KEYCODE_AVR_POWER");
2876         names.append(KEYCODE_AVR_INPUT, "KEYCODE_AVR_INPUT");
2877         names.append(KEYCODE_PROG_RED, "KEYCODE_PROG_RED");
2878         names.append(KEYCODE_PROG_GREEN, "KEYCODE_PROG_GREEN");
2879         names.append(KEYCODE_PROG_YELLOW, "KEYCODE_PROG_YELLOW");
2880         names.append(KEYCODE_PROG_BLUE, "KEYCODE_PROG_BLUE");
2881         names.append(KEYCODE_APP_SWITCH, "KEYCODE_APP_SWITCH");
2882         names.append(KEYCODE_BUTTON_1, "KEYCODE_BUTTON_1");
2883         names.append(KEYCODE_BUTTON_2, "KEYCODE_BUTTON_2");
2884         names.append(KEYCODE_BUTTON_3, "KEYCODE_BUTTON_3");
2885         names.append(KEYCODE_BUTTON_4, "KEYCODE_BUTTON_4");
2886         names.append(KEYCODE_BUTTON_5, "KEYCODE_BUTTON_5");
2887         names.append(KEYCODE_BUTTON_6, "KEYCODE_BUTTON_6");
2888         names.append(KEYCODE_BUTTON_7, "KEYCODE_BUTTON_7");
2889         names.append(KEYCODE_BUTTON_8, "KEYCODE_BUTTON_8");
2890         names.append(KEYCODE_BUTTON_9, "KEYCODE_BUTTON_9");
2891         names.append(KEYCODE_BUTTON_10, "KEYCODE_BUTTON_10");
2892         names.append(KEYCODE_BUTTON_11, "KEYCODE_BUTTON_11");
2893         names.append(KEYCODE_BUTTON_12, "KEYCODE_BUTTON_12");
2894         names.append(KEYCODE_BUTTON_13, "KEYCODE_BUTTON_13");
2895         names.append(KEYCODE_BUTTON_14, "KEYCODE_BUTTON_14");
2896         names.append(KEYCODE_BUTTON_15, "KEYCODE_BUTTON_15");
2897         names.append(KEYCODE_BUTTON_16, "KEYCODE_BUTTON_16");
2898         names.append(KEYCODE_LANGUAGE_SWITCH, "KEYCODE_LANGUAGE_SWITCH");
2899         names.append(KEYCODE_MANNER_MODE, "KEYCODE_MANNER_MODE");
2900         names.append(KEYCODE_3D_MODE, "KEYCODE_3D_MODE");
2901         names.append(KEYCODE_CONTACTS, "KEYCODE_CONTACTS");
2902         names.append(KEYCODE_CALENDAR, "KEYCODE_CALENDAR");
2903         names.append(KEYCODE_MUSIC, "KEYCODE_MUSIC");
2904         names.append(KEYCODE_CALCULATOR, "KEYCODE_CALCULATOR");
2905         names.append(KEYCODE_ZENKAKU_HANKAKU, "KEYCODE_ZENKAKU_HANKAKU");
2906         names.append(KEYCODE_EISU, "KEYCODE_EISU");
2907         names.append(KEYCODE_MUHENKAN, "KEYCODE_MUHENKAN");
2908         names.append(KEYCODE_HENKAN, "KEYCODE_HENKAN");
2909         names.append(KEYCODE_KATAKANA_HIRAGANA, "KEYCODE_KATAKANA_HIRAGANA");
2910         names.append(KEYCODE_YEN, "KEYCODE_YEN");
2911         names.append(KEYCODE_RO, "KEYCODE_RO");
2912         names.append(KEYCODE_KANA, "KEYCODE_KANA");
2913         names.append(KEYCODE_ASSIST, "KEYCODE_ASSIST");
2914     };
2915 
2916     // Symbolic names of all metakeys in bit order from least significant to most significant.
2917     // Accordingly there are exactly 32 values in this table.
2918     private static final String[] META_SYMBOLIC_NAMES = new String[] {
2919         "META_SHIFT_ON",
2920         "META_ALT_ON",
2921         "META_SYM_ON",
2922         "META_FUNCTION_ON",
2923         "META_ALT_LEFT_ON",
2924         "META_ALT_RIGHT_ON",
2925         "META_SHIFT_LEFT_ON",
2926         "META_SHIFT_RIGHT_ON",
2927         "META_CAP_LOCKED",
2928         "META_ALT_LOCKED",
2929         "META_SYM_LOCKED",
2930         "0x00000800",
2931         "META_CTRL_ON",
2932         "META_CTRL_LEFT_ON",
2933         "META_CTRL_RIGHT_ON",
2934         "0x00008000",
2935         "META_META_ON",
2936         "META_META_LEFT_ON",
2937         "META_META_RIGHT_ON",
2938         "0x00080000",
2939         "META_CAPS_LOCK_ON",
2940         "META_NUM_LOCK_ON",
2941         "META_SCROLL_LOCK_ON",
2942         "0x00800000",
2943         "0x01000000",
2944         "0x02000000",
2945         "0x04000000",
2946         "0x08000000",
2947         "0x10000000",
2948         "0x20000000",
2949         "0x40000000",
2950         "0x80000000",
2951     };
2952 
2953     /**
2954      * @deprecated There are now more than MAX_KEYCODE keycodes.
2955      * Use {@link #getMaxKeyCode()} instead.
2956      */
2957     @Deprecated
2958     public static final int MAX_KEYCODE             = 84;
2959 
2960     /**
2961      * {@link #getAction} value: the key has been pressed down.
2962      */
2963     public static final int ACTION_DOWN             = 0;
2964     /**
2965      * {@link #getAction} value: the key has been released.
2966      */
2967     public static final int ACTION_UP               = 1;
2968     /**
2969      * {@link #getAction} value: multiple duplicate key events have
2970      * occurred in a row, or a complex string is being delivered.  If the
2971      * key code is not {#link {@link #KEYCODE_UNKNOWN} then the
2972      * {#link {@link #getRepeatCount()} method returns the number of times
2973      * the given key code should be executed.
2974      * Otherwise, if the key code is {@link #KEYCODE_UNKNOWN}, then
2975      * this is a sequence of characters as returned by {@link #getCharacters}.
2976      */
2977     public static final int ACTION_MULTIPLE         = 2;
2978 
2979     /**
2980      * SHIFT key locked in CAPS mode.
2981      * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API.
2982      * @hide
2983      */
2984     public static final int META_CAP_LOCKED = 0x100;
2985 
2986     /**
2987      * ALT key locked.
2988      * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API.
2989      * @hide
2990      */
2991     public static final int META_ALT_LOCKED = 0x200;
2992 
2993     /**
2994      * SYM key locked.
2995      * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API.
2996      * @hide
2997      */
2998     public static final int META_SYM_LOCKED = 0x400;
2999 
3000     /**
3001      * Text is in selection mode.
3002      * Reserved for use by {@link MetaKeyKeyListener} for a private unpublished constant
3003      * in its API that is currently being retained for legacy reasons.
3004      * @hide
3005      */
3006     public static final int META_SELECTING = 0x800;
3007 
3008     /**
3009      * <p>This mask is used to check whether one of the ALT meta keys is pressed.</p>
3010      *
3011      * @see #isAltPressed()
3012      * @see #getMetaState()
3013      * @see #KEYCODE_ALT_LEFT
3014      * @see #KEYCODE_ALT_RIGHT
3015      */
3016     public static final int META_ALT_ON = 0x02;
3017 
3018     /**
3019      * <p>This mask is used to check whether the left ALT meta key is pressed.</p>
3020      *
3021      * @see #isAltPressed()
3022      * @see #getMetaState()
3023      * @see #KEYCODE_ALT_LEFT
3024      */
3025     public static final int META_ALT_LEFT_ON = 0x10;
3026 
3027     /**
3028      * <p>This mask is used to check whether the right the ALT meta key is pressed.</p>
3029      *
3030      * @see #isAltPressed()
3031      * @see #getMetaState()
3032      * @see #KEYCODE_ALT_RIGHT
3033      */
3034     public static final int META_ALT_RIGHT_ON = 0x20;
3035 
3036     /**
3037      * <p>This mask is used to check whether one of the SHIFT meta keys is pressed.</p>
3038      *
3039      * @see #isShiftPressed()
3040      * @see #getMetaState()
3041      * @see #KEYCODE_SHIFT_LEFT
3042      * @see #KEYCODE_SHIFT_RIGHT
3043      */
3044     public static final int META_SHIFT_ON = 0x1;
3045 
3046     /**
3047      * <p>This mask is used to check whether the left SHIFT meta key is pressed.</p>
3048      *
3049      * @see #isShiftPressed()
3050      * @see #getMetaState()
3051      * @see #KEYCODE_SHIFT_LEFT
3052      */
3053     public static final int META_SHIFT_LEFT_ON = 0x40;
3054 
3055     /**
3056      * <p>This mask is used to check whether the right SHIFT meta key is pressed.</p>
3057      *
3058      * @see #isShiftPressed()
3059      * @see #getMetaState()
3060      * @see #KEYCODE_SHIFT_RIGHT
3061      */
3062     public static final int META_SHIFT_RIGHT_ON = 0x80;
3063 
3064     /**
3065      * <p>This mask is used to check whether the SYM meta key is pressed.</p>
3066      *
3067      * @see #isSymPressed()
3068      * @see #getMetaState()
3069      */
3070     public static final int META_SYM_ON = 0x4;
3071 
3072     /**
3073      * <p>This mask is used to check whether the FUNCTION meta key is pressed.</p>
3074      *
3075      * @see #isFunctionPressed()
3076      * @see #getMetaState()
3077      */
3078     public static final int META_FUNCTION_ON = 0x8;
3079 
3080     /**
3081      * <p>This mask is used to check whether one of the CTRL meta keys is pressed.</p>
3082      *
3083      * @see #isCtrlPressed()
3084      * @see #getMetaState()
3085      * @see #KEYCODE_CTRL_LEFT
3086      * @see #KEYCODE_CTRL_RIGHT
3087      */
3088     public static final int META_CTRL_ON = 0x1000;
3089 
3090     /**
3091      * <p>This mask is used to check whether the left CTRL meta key is pressed.</p>
3092      *
3093      * @see #isCtrlPressed()
3094      * @see #getMetaState()
3095      * @see #KEYCODE_CTRL_LEFT
3096      */
3097     public static final int META_CTRL_LEFT_ON = 0x2000;
3098 
3099     /**
3100      * <p>This mask is used to check whether the right CTRL meta key is pressed.</p>
3101      *
3102      * @see #isCtrlPressed()
3103      * @see #getMetaState()
3104      * @see #KEYCODE_CTRL_RIGHT
3105      */
3106     public static final int META_CTRL_RIGHT_ON = 0x4000;
3107 
3108     /**
3109      * <p>This mask is used to check whether one of the META meta keys is pressed.</p>
3110      *
3111      * @see #isMetaPressed()
3112      * @see #getMetaState()
3113      * @see #KEYCODE_META_LEFT
3114      * @see #KEYCODE_META_RIGHT
3115      */
3116     public static final int META_META_ON = 0x10000;
3117 
3118     /**
3119      * <p>This mask is used to check whether the left META meta key is pressed.</p>
3120      *
3121      * @see #isMetaPressed()
3122      * @see #getMetaState()
3123      * @see #KEYCODE_META_LEFT
3124      */
3125     public static final int META_META_LEFT_ON = 0x20000;
3126 
3127     /**
3128      * <p>This mask is used to check whether the right META meta key is pressed.</p>
3129      *
3130      * @see #isMetaPressed()
3131      * @see #getMetaState()
3132      * @see #KEYCODE_META_RIGHT
3133      */
3134     public static final int META_META_RIGHT_ON = 0x40000;
3135 
3136     /**
3137      * <p>This mask is used to check whether the CAPS LOCK meta key is on.</p>
3138      *
3139      * @see #isCapsLockOn()
3140      * @see #getMetaState()
3141      * @see #KEYCODE_CAPS_LOCK
3142      */
3143     public static final int META_CAPS_LOCK_ON = 0x100000;
3144 
3145     /**
3146      * <p>This mask is used to check whether the NUM LOCK meta key is on.</p>
3147      *
3148      * @see #isNumLockOn()
3149      * @see #getMetaState()
3150      * @see #KEYCODE_NUM_LOCK
3151      */
3152     public static final int META_NUM_LOCK_ON = 0x200000;
3153 
3154     /**
3155      * <p>This mask is used to check whether the SCROLL LOCK meta key is on.</p>
3156      *
3157      * @see #isScrollLockOn()
3158      * @see #getMetaState()
3159      * @see #KEYCODE_SCROLL_LOCK
3160      */
3161     public static final int META_SCROLL_LOCK_ON = 0x400000;
3162 
3163     /**
3164      * This mask is a combination of {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}
3165      * and {@link #META_SHIFT_RIGHT_ON}.
3166      */
3167     public static final int META_SHIFT_MASK = META_SHIFT_ON
3168             | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON;
3169 
3170     /**
3171      * This mask is a combination of {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}
3172      * and {@link #META_ALT_RIGHT_ON}.
3173      */
3174     public static final int META_ALT_MASK = META_ALT_ON
3175             | META_ALT_LEFT_ON | META_ALT_RIGHT_ON;
3176 
3177     /**
3178      * This mask is a combination of {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}
3179      * and {@link #META_CTRL_RIGHT_ON}.
3180      */
3181     public static final int META_CTRL_MASK = META_CTRL_ON
3182             | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON;
3183 
3184     /**
3185      * This mask is a combination of {@link #META_META_ON}, {@link #META_META_LEFT_ON}
3186      * and {@link #META_META_RIGHT_ON}.
3187      */
3188     public static final int META_META_MASK = META_META_ON
3189             | META_META_LEFT_ON | META_META_RIGHT_ON;
3190 
3191     /**
3192      * This mask is set if the device woke because of this key event.
3193      */
3194     public static final int FLAG_WOKE_HERE = 0x1;
3195     
3196     /**
3197      * This mask is set if the key event was generated by a software keyboard.
3198      */
3199     public static final int FLAG_SOFT_KEYBOARD = 0x2;
3200     
3201     /**
3202      * This mask is set if we don't want the key event to cause us to leave
3203      * touch mode.
3204      */
3205     public static final int FLAG_KEEP_TOUCH_MODE = 0x4;
3206     
3207     /**
3208      * This mask is set if an event was known to come from a trusted part
3209      * of the system.  That is, the event is known to come from the user,
3210      * and could not have been spoofed by a third party component.
3211      */
3212     public static final int FLAG_FROM_SYSTEM = 0x8;
3213     
3214     /**
3215      * This mask is used for compatibility, to identify enter keys that are
3216      * coming from an IME whose enter key has been auto-labelled "next" or
3217      * "done".  This allows TextView to dispatch these as normal enter keys
3218      * for old applications, but still do the appropriate action when
3219      * receiving them.
3220      */
3221     public static final int FLAG_EDITOR_ACTION = 0x10;
3222     
3223     /**
3224      * When associated with up key events, this indicates that the key press
3225      * has been canceled.  Typically this is used with virtual touch screen
3226      * keys, where the user can slide from the virtual key area on to the
3227      * display: in that case, the application will receive a canceled up
3228      * event and should not perform the action normally associated with the
3229      * key.  Note that for this to work, the application can not perform an
3230      * action for a key until it receives an up or the long press timeout has
3231      * expired. 
3232      */
3233     public static final int FLAG_CANCELED = 0x20;
3234     
3235     /**
3236      * This key event was generated by a virtual (on-screen) hard key area.
3237      * Typically this is an area of the touchscreen, outside of the regular
3238      * display, dedicated to "hardware" buttons.
3239      */
3240     public static final int FLAG_VIRTUAL_HARD_KEY = 0x40;
3241     
3242     /**
3243      * This flag is set for the first key repeat that occurs after the
3244      * long press timeout.
3245      */
3246     public static final int FLAG_LONG_PRESS = 0x80;
3247     
3248     /**
3249      * Set when a key event has {@link #FLAG_CANCELED} set because a long
3250      * press action was executed while it was down. 
3251      */
3252     public static final int FLAG_CANCELED_LONG_PRESS = 0x100;
3253     
3254     /**
3255      * Set for {@link #ACTION_UP} when this event's key code is still being
3256      * tracked from its initial down.  That is, somebody requested that tracking
3257      * started on the key down and a long press has not caused
3258      * the tracking to be canceled.
3259      */
3260     public static final int FLAG_TRACKING = 0x200;
3261 
3262     /**
3263      * Set when a key event has been synthesized to implement default behavior
3264      * for an event that the application did not handle.
3265      * Fallback key events are generated by unhandled trackball motions
3266      * (to emulate a directional keypad) and by certain unhandled key presses
3267      * that are declared in the key map (such as special function numeric keypad
3268      * keys when numlock is off).
3269      */
3270     public static final int FLAG_FALLBACK = 0x400;
3271 
3272     /**
3273      * Private control to determine when an app is tracking a key sequence.
3274      * @hide
3275      */
3276     public static final int FLAG_START_TRACKING = 0x40000000;
3277 
3278     /**
3279      * Private flag that indicates when the system has detected that this key event
3280      * may be inconsistent with respect to the sequence of previously delivered key events,
3281      * such as when a key up event is sent but the key was not down.
3282      *
3283      * @hide
3284      * @see #isTainted
3285      * @see #setTainted
3286      */
3287     public static final int FLAG_TAINTED = 0x80000000;
3288 
3289     /**
3290      * Returns the maximum keycode.
3291      */
3292     public static int getMaxKeyCode() {
3293         return LAST_KEYCODE;
3294     }
3295 
3296     /**
3297      * Get the character that is produced by putting accent on the character
3298      * c.
3299      * For example, getDeadChar('`', 'e') returns è.
3300      */
3301     public static int getDeadChar(int accent, int c) {
3302         return KeyCharacterMap.getDeadChar(accent, c);
3303     }
3304     
3305     static final boolean DEBUG = false;
3306     static final String TAG = "KeyEvent";
3307 
3308     private static final int MAX_RECYCLED = 10;
3309     private static final Object gRecyclerLock = new Object();
3310     private static int gRecyclerUsed;
3311     private static KeyEvent gRecyclerTop;
3312 
3313     private KeyEvent mNext;
3314 
3315     private int mDeviceId;
3316     private int mSource;
3317     private int mMetaState;
3318     private int mAction;
3319     private int mKeyCode;
3320     private int mScanCode;
3321     private int mRepeatCount;
3322     private int mFlags;
3323     private long mDownTime;
3324     private long mEventTime;
3325     private String mCharacters;
3326 
3327     public interface Callback {
3328         /**
3329          * Called when a key down event has occurred.  If you return true,
3330          * you can first call {@link KeyEvent#startTracking()
3331          * KeyEvent.startTracking()} to have the framework track the event
3332          * through its {@link #onKeyUp(int, KeyEvent)} and also call your
3333          * {@link #onKeyLongPress(int, KeyEvent)} if it occurs.
3334          * 
3335          * @param keyCode The value in event.getKeyCode().
3336          * @param event Description of the key event.
3337          * 
3338          * @return If you handled the event, return true.  If you want to allow
3339          *         the event to be handled by the next receiver, return false.
3340          */
3341         boolean onKeyDown(int keyCode, KeyEvent event);
3342 
3343         /**
3344          * Called when a long press has occurred.  If you return true,
3345          * the final key up will have {@link KeyEvent#FLAG_CANCELED} and
3346          * {@link KeyEvent#FLAG_CANCELED_LONG_PRESS} set.  Note that in
3347          * order to receive this callback, someone in the event change
3348          * <em>must</em> return true from {@link #onKeyDown} <em>and</em>
3349          * call {@link KeyEvent#startTracking()} on the event.
3350          * 
3351          * @param keyCode The value in event.getKeyCode().
3352          * @param event Description of the key event.
3353          * 
3354          * @return If you handled the event, return true.  If you want to allow
3355          *         the event to be handled by the next receiver, return false.
3356          */
3357         boolean onKeyLongPress(int keyCode, KeyEvent event);
3358 
3359         /**
3360          * Called when a key up event has occurred.
3361          * 
3362          * @param keyCode The value in event.getKeyCode().
3363          * @param event Description of the key event.
3364          * 
3365          * @return If you handled the event, return true.  If you want to allow
3366          *         the event to be handled by the next receiver, return false.
3367          */
3368         boolean onKeyUp(int keyCode, KeyEvent event);
3369 
3370         /**
3371          * Called when multiple down/up pairs of the same key have occurred
3372          * in a row.
3373          * 
3374          * @param keyCode The value in event.getKeyCode().
3375          * @param count Number of pairs as returned by event.getRepeatCount().
3376          * @param event Description of the key event.
3377          * 
3378          * @return If you handled the event, return true.  If you want to allow
3379          *         the event to be handled by the next receiver, return false.
3380          */
3381         boolean onKeyMultiple(int keyCode, int count, KeyEvent event);
3382     }
3383 
3384     static {
3385         populateKeycodeSymbolicNames();
3386     }
3387 
3388     private KeyEvent() {
3389     }
3390 
3391     /**
3392      * Create a new key event.
3393      * 
3394      * @param action Action code: either {@link #ACTION_DOWN},
3395      * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
3396      * @param code The key code.
3397      */
3398     public KeyEvent(int action, int code) {
3399         mAction = action;
3400         mKeyCode = code;
3401         mRepeatCount = 0;
3402         mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD;
3403     }
3404 
3405     /**
3406      * Create a new key event.
3407      * 
3408      * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
3409      * at which this key code originally went down.
3410      * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
3411      * at which this event happened.
3412      * @param action Action code: either {@link #ACTION_DOWN},
3413      * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
3414      * @param code The key code.
3415      * @param repeat A repeat count for down events (> 0 if this is after the
3416      * initial down) or event count for multiple events.
3417      */
3418     public KeyEvent(long downTime, long eventTime, int action,
3419                     int code, int repeat) {
3420         mDownTime = downTime;
3421         mEventTime = eventTime;
3422         mAction = action;
3423         mKeyCode = code;
3424         mRepeatCount = repeat;
3425         mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD;
3426     }
3427 
3428     /**
3429      * Create a new key event.
3430      * 
3431      * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
3432      * at which this key code originally went down.
3433      * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
3434      * at which this event happened.
3435      * @param action Action code: either {@link #ACTION_DOWN},
3436      * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
3437      * @param code The key code.
3438      * @param repeat A repeat count for down events (> 0 if this is after the
3439      * initial down) or event count for multiple events.
3440      * @param metaState Flags indicating which meta keys are currently pressed.
3441      */
3442     public KeyEvent(long downTime, long eventTime, int action,
3443                     int code, int repeat, int metaState) {
3444         mDownTime = downTime;
3445         mEventTime = eventTime;
3446         mAction = action;
3447         mKeyCode = code;
3448         mRepeatCount = repeat;
3449         mMetaState = metaState;
3450         mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD;
3451     }
3452 
3453     /**
3454      * Create a new key event.
3455      * 
3456      * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
3457      * at which this key code originally went down.
3458      * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
3459      * at which this event happened.
3460      * @param action Action code: either {@link #ACTION_DOWN},
3461      * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
3462      * @param code The key code.
3463      * @param repeat A repeat count for down events (> 0 if this is after the
3464      * initial down) or event count for multiple events.
3465      * @param metaState Flags indicating which meta keys are currently pressed.
3466      * @param deviceId The device ID that generated the key event.
3467      * @param scancode Raw device scan code of the event.
3468      */
3469     public KeyEvent(long downTime, long eventTime, int action,
3470                     int code, int repeat, int metaState,
3471                     int deviceId, int scancode) {
3472         mDownTime = downTime;
3473         mEventTime = eventTime;
3474         mAction = action;
3475         mKeyCode = code;
3476         mRepeatCount = repeat;
3477         mMetaState = metaState;
3478         mDeviceId = deviceId;
3479         mScanCode = scancode;
3480     }
3481 
3482     /**
3483      * Create a new key event.
3484      * 
3485      * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
3486      * at which this key code originally went down.
3487      * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
3488      * at which this event happened.
3489      * @param action Action code: either {@link #ACTION_DOWN},
3490      * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
3491      * @param code The key code.
3492      * @param repeat A repeat count for down events (> 0 if this is after the
3493      * initial down) or event count for multiple events.
3494      * @param metaState Flags indicating which meta keys are currently pressed.
3495      * @param deviceId The device ID that generated the key event.
3496      * @param scancode Raw device scan code of the event.
3497      * @param flags The flags for this key event
3498      */
3499     public KeyEvent(long downTime, long eventTime, int action,
3500                     int code, int repeat, int metaState,
3501                     int deviceId, int scancode, int flags) {
3502         mDownTime = downTime;
3503         mEventTime = eventTime;
3504         mAction = action;
3505         mKeyCode = code;
3506         mRepeatCount = repeat;
3507         mMetaState = metaState;
3508         mDeviceId = deviceId;
3509         mScanCode = scancode;
3510         mFlags = flags;
3511     }
3512 
3513     /**
3514      * Create a new key event.
3515      * 
3516      * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
3517      * at which this key code originally went down.
3518      * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
3519      * at which this event happened.
3520      * @param action Action code: either {@link #ACTION_DOWN},
3521      * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
3522      * @param code The key code.
3523      * @param repeat A repeat count for down events (> 0 if this is after the
3524      * initial down) or event count for multiple events.
3525      * @param metaState Flags indicating which meta keys are currently pressed.
3526      * @param deviceId The device ID that generated the key event.
3527      * @param scancode Raw device scan code of the event.
3528      * @param flags The flags for this key event
3529      * @param source The input source such as {@link InputDevice#SOURCE_KEYBOARD}.
3530      */
3531     public KeyEvent(long downTime, long eventTime, int action,
3532                     int code, int repeat, int metaState,
3533                     int deviceId, int scancode, int flags, int source) {
3534         mDownTime = downTime;
3535         mEventTime = eventTime;
3536         mAction = action;
3537         mKeyCode = code;
3538         mRepeatCount = repeat;
3539         mMetaState = metaState;
3540         mDeviceId = deviceId;
3541         mScanCode = scancode;
3542         mFlags = flags;
3543         mSource = source;
3544     }
3545 
3546     /**
3547      * Create a new key event for a string of characters.  The key code,
3548      * action, repeat count and source will automatically be set to
3549      * {@link #KEYCODE_UNKNOWN}, {@link #ACTION_MULTIPLE}, 0, and
3550      * {@link InputDevice#SOURCE_KEYBOARD} for you.
3551      * 
3552      * @param time The time (in {@link android.os.SystemClock#uptimeMillis})
3553      * at which this event occured.
3554      * @param characters The string of characters.
3555      * @param deviceId The device ID that generated the key event.
3556      * @param flags The flags for this key event
3557      */
3558     public KeyEvent(long time, String characters, int deviceId, int flags) {
3559         mDownTime = time;
3560         mEventTime = time;
3561         mCharacters = characters;
3562         mAction = ACTION_MULTIPLE;
3563         mKeyCode = KEYCODE_UNKNOWN;
3564         mRepeatCount = 0;
3565         mDeviceId = deviceId;
3566         mFlags = flags;
3567         mSource = InputDevice.SOURCE_KEYBOARD;
3568     }
3569 
3570     /**
3571      * Make an exact copy of an existing key event.
3572      */
3573     public KeyEvent(KeyEvent origEvent) {
3574         mDownTime = origEvent.mDownTime;
3575         mEventTime = origEvent.mEventTime;
3576         mAction = origEvent.mAction;
3577         mKeyCode = origEvent.mKeyCode;
3578         mRepeatCount = origEvent.mRepeatCount;
3579         mMetaState = origEvent.mMetaState;
3580         mDeviceId = origEvent.mDeviceId;
3581         mSource = origEvent.mSource;
3582         mScanCode = origEvent.mScanCode;
3583         mFlags = origEvent.mFlags;
3584         mCharacters = origEvent.mCharacters;
3585     }
3586 
3587     /**
3588      * Copy an existing key event, modifying its time and repeat count.
3589      * 
3590      * @deprecated Use {@link #changeTimeRepeat(KeyEvent, long, int)}
3591      * instead.
3592      * 
3593      * @param origEvent The existing event to be copied.
3594      * @param eventTime The new event time
3595      * (in {@link android.os.SystemClock#uptimeMillis}) of the event.
3596      * @param newRepeat The new repeat count of the event.
3597      */
3598     @Deprecated
3599     public KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat) {
3600         mDownTime = origEvent.mDownTime;
3601         mEventTime = eventTime;
3602         mAction = origEvent.mAction;
3603         mKeyCode = origEvent.mKeyCode;
3604         mRepeatCount = newRepeat;
3605         mMetaState = origEvent.mMetaState;
3606         mDeviceId = origEvent.mDeviceId;
3607         mSource = origEvent.mSource;
3608         mScanCode = origEvent.mScanCode;
3609         mFlags = origEvent.mFlags;
3610         mCharacters = origEvent.mCharacters;
3611     }
3612 
3613     private static KeyEvent obtain() {
3614         final KeyEvent ev;
3615         synchronized (gRecyclerLock) {
3616             ev = gRecyclerTop;
3617             if (ev == null) {
3618                 return new KeyEvent();
3619             }
3620             gRecyclerTop = ev.mNext;
3621             gRecyclerUsed -= 1;
3622         }
3623         ev.mNext = null;
3624         ev.prepareForReuse();
3625         return ev;
3626     }
3627 
3628     /**
3629      * Obtains a (potentially recycled) key event.
3630      *
3631      * @hide
3632      */
3633     public static KeyEvent obtain(long downTime, long eventTime, int action,
3634                     int code, int repeat, int metaState,
3635                     int deviceId, int scancode, int flags, int source, String characters) {
3636         KeyEvent ev = obtain();
3637         ev.mDownTime = downTime;
3638         ev.mEventTime = eventTime;
3639         ev.mAction = action;
3640         ev.mKeyCode = code;
3641         ev.mRepeatCount = repeat;
3642         ev.mMetaState = metaState;
3643         ev.mDeviceId = deviceId;
3644         ev.mScanCode = scancode;
3645         ev.mFlags = flags;
3646         ev.mSource = source;
3647         ev.mCharacters = characters;
3648         return ev;
3649     }
3650 
3651     /**
3652      * Obtains a (potentially recycled) copy of another key event.
3653      *
3654      * @hide
3655      */
3656     public static KeyEvent obtain(KeyEvent other) {
3657         KeyEvent ev = obtain();
3658         ev.mDownTime = other.mDownTime;
3659         ev.mEventTime = other.mEventTime;
3660         ev.mAction = other.mAction;
3661         ev.mKeyCode = other.mKeyCode;
3662         ev.mRepeatCount = other.mRepeatCount;
3663         ev.mMetaState = other.mMetaState;
3664         ev.mDeviceId = other.mDeviceId;
3665         ev.mScanCode = other.mScanCode;
3666         ev.mFlags = other.mFlags;
3667         ev.mSource = other.mSource;
3668         ev.mCharacters = other.mCharacters;
3669         return ev;
3670     }
3671 
3672     /** @hide */
3673     @Override
3674     public KeyEvent copy() {
3675         return obtain(this);
3676     }
3677 
3678     /**
3679      * Recycles a key event.
3680      * Key events should only be recycled if they are owned by the system since user
3681      * code expects them to be essentially immutable, "tracking" notwithstanding.
3682      *
3683      * @hide
3684      */
3685     @Override
3686     public final void recycle() {
3687         super.recycle();
3688         mCharacters = null;
3689 
3690         synchronized (gRecyclerLock) {
3691             if (gRecyclerUsed < MAX_RECYCLED) {
3692                 gRecyclerUsed++;
3693                 mNext = gRecyclerTop;
3694                 gRecyclerTop = this;
3695             }
3696         }
3697     }
3698 
3699     /** @hide */
3700     @Override
3701     public final void recycleIfNeededAfterDispatch() {
3702         // Do nothing.
3703     }
3704 
3705     /**
3706      * Create a new key event that is the same as the given one, but whose
3707      * event time and repeat count are replaced with the given value.
3708      * 
3709      * @param event The existing event to be copied.  This is not modified.
3710      * @param eventTime The new event time
3711      * (in {@link android.os.SystemClock#uptimeMillis}) of the event.
3712      * @param newRepeat The new repeat count of the event.
3713      */
3714     public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime,
3715             int newRepeat) {
3716         return new KeyEvent(event, eventTime, newRepeat);
3717     }
3718     
3719     /**
3720      * Create a new key event that is the same as the given one, but whose
3721      * event time and repeat count are replaced with the given value.
3722      * 
3723      * @param event The existing event to be copied.  This is not modified.
3724      * @param eventTime The new event time
3725      * (in {@link android.os.SystemClock#uptimeMillis}) of the event.
3726      * @param newRepeat The new repeat count of the event.
3727      * @param newFlags New flags for the event, replacing the entire value
3728      * in the original event.
3729      */
3730     public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime,
3731             int newRepeat, int newFlags) {
3732         KeyEvent ret = new KeyEvent(event);
3733         ret.mEventTime = eventTime;
3734         ret.mRepeatCount = newRepeat;
3735         ret.mFlags = newFlags;
3736         return ret;
3737     }
3738     
3739     /**
3740      * Copy an existing key event, modifying its action.
3741      * 
3742      * @param origEvent The existing event to be copied.
3743      * @param action The new action code of the event.
3744      */
3745     private KeyEvent(KeyEvent origEvent, int action) {
3746         mDownTime = origEvent.mDownTime;
3747         mEventTime = origEvent.mEventTime;
3748         mAction = action;
3749         mKeyCode = origEvent.mKeyCode;
3750         mRepeatCount = origEvent.mRepeatCount;
3751         mMetaState = origEvent.mMetaState;
3752         mDeviceId = origEvent.mDeviceId;
3753         mSource = origEvent.mSource;
3754         mScanCode = origEvent.mScanCode;
3755         mFlags = origEvent.mFlags;
3756         // Don't copy mCharacters, since one way or the other we'll lose it
3757         // when changing the action.
3758     }
3759 
3760     /**
3761      * Create a new key event that is the same as the given one, but whose
3762      * action is replaced with the given value.
3763      * 
3764      * @param event The existing event to be copied.  This is not modified.
3765      * @param action The new action code of the event.
3766      */
3767     public static KeyEvent changeAction(KeyEvent event, int action) {
3768         return new KeyEvent(event, action);
3769     }
3770     
3771     /**
3772      * Create a new key event that is the same as the given one, but whose
3773      * flags are replaced with the given value.
3774      * 
3775      * @param event The existing event to be copied.  This is not modified.
3776      * @param flags The new flags constant.
3777      */
3778     public static KeyEvent changeFlags(KeyEvent event, int flags) {
3779         event = new KeyEvent(event);
3780         event.mFlags = flags;
3781         return event;
3782     }
3783 
3784     /** @hide */
3785     @Override
3786     public final boolean isTainted() {
3787         return (mFlags & FLAG_TAINTED) != 0;
3788     }
3789 
3790     /** @hide */
3791     @Override
3792     public final void setTainted(boolean tainted) {
3793         mFlags = tainted ? mFlags | FLAG_TAINTED : mFlags & ~FLAG_TAINTED;
3794     }
3795 
3796     /**
3797      * Don't use in new code, instead explicitly check
3798      * {@link #getAction()}.
3799      * 
3800      * @return If the action is ACTION_DOWN, returns true; else false.
3801      *
3802      * @deprecated
3803      * @hide
3804      */
3805     @Deprecated public final boolean isDown() {
3806         return mAction == ACTION_DOWN;
3807     }
3808 
3809     /**
3810      * Is this a system key?  System keys can not be used for menu shortcuts.
3811      * 
3812      * TODO: this information should come from a table somewhere.
3813      * TODO: should the dpad keys be here?  arguably, because they also shouldn't be menu shortcuts
3814      */
3815     public final boolean isSystem() {
3816         return native_isSystemKey(mKeyCode);
3817     }
3818 
3819     /** @hide */
3820     public final boolean hasDefaultAction() {
3821         return native_hasDefaultAction(mKeyCode);
3822     }
3823 
3824     /**
3825      * Returns true if the specified keycode is a gamepad button.
3826      * @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}.
3827      */
3828     public static final boolean isGamepadButton(int keyCode) {
3829         switch (keyCode) {
3830             case KeyEvent.KEYCODE_BUTTON_A:
3831             case KeyEvent.KEYCODE_BUTTON_B:
3832             case KeyEvent.KEYCODE_BUTTON_C:
3833             case KeyEvent.KEYCODE_BUTTON_X:
3834             case KeyEvent.KEYCODE_BUTTON_Y:
3835             case KeyEvent.KEYCODE_BUTTON_Z:
3836             case KeyEvent.KEYCODE_BUTTON_L1:
3837             case KeyEvent.KEYCODE_BUTTON_R1:
3838             case KeyEvent.KEYCODE_BUTTON_L2:
3839             case KeyEvent.KEYCODE_BUTTON_R2:
3840             case KeyEvent.KEYCODE_BUTTON_THUMBL:
3841             case KeyEvent.KEYCODE_BUTTON_THUMBR:
3842             case KeyEvent.KEYCODE_BUTTON_START:
3843             case KeyEvent.KEYCODE_BUTTON_SELECT:
3844             case KeyEvent.KEYCODE_BUTTON_MODE:
3845             case KeyEvent.KEYCODE_BUTTON_1:
3846             case KeyEvent.KEYCODE_BUTTON_2:
3847             case KeyEvent.KEYCODE_BUTTON_3:
3848             case KeyEvent.KEYCODE_BUTTON_4:
3849             case KeyEvent.KEYCODE_BUTTON_5:
3850             case KeyEvent.KEYCODE_BUTTON_6:
3851             case KeyEvent.KEYCODE_BUTTON_7:
3852             case KeyEvent.KEYCODE_BUTTON_8:
3853             case KeyEvent.KEYCODE_BUTTON_9:
3854             case KeyEvent.KEYCODE_BUTTON_10:
3855             case KeyEvent.KEYCODE_BUTTON_11:
3856             case KeyEvent.KEYCODE_BUTTON_12:
3857             case KeyEvent.KEYCODE_BUTTON_13:
3858             case KeyEvent.KEYCODE_BUTTON_14:
3859             case KeyEvent.KEYCODE_BUTTON_15:
3860             case KeyEvent.KEYCODE_BUTTON_16:
3861                 return true;
3862             default:
3863                 return false;
3864         }
3865     }
3866 
3867     /** {@inheritDoc} */
3868     @Override
3869     public final int getDeviceId() {
3870         return mDeviceId;
3871     }
3872 
3873     /** {@inheritDoc} */
3874     @Override
3875     public final int getSource() {
3876         return mSource;
3877     }
3878 
3879     /** {@inheritDoc} */
3880     @Override
3881     public final void setSource(int source) {
3882         mSource = source;
3883     }
3884 
3885     /**
3886      * <p>Returns the state of the meta keys.</p>
3887      *
3888      * @return an integer in which each bit set to 1 represents a pressed
3889      *         meta key
3890      *
3891      * @see #isAltPressed()
3892      * @see #isShiftPressed()
3893      * @see #isSymPressed()
3894      * @see #isCtrlPressed()
3895      * @see #isMetaPressed()
3896      * @see #isFunctionPressed()
3897      * @see #isCapsLockOn()
3898      * @see #isNumLockOn()
3899      * @see #isScrollLockOn()
3900      * @see #META_ALT_ON
3901      * @see #META_ALT_LEFT_ON
3902      * @see #META_ALT_RIGHT_ON
3903      * @see #META_SHIFT_ON
3904      * @see #META_SHIFT_LEFT_ON
3905      * @see #META_SHIFT_RIGHT_ON
3906      * @see #META_SYM_ON
3907      * @see #META_FUNCTION_ON
3908      * @see #META_CTRL_ON
3909      * @see #META_CTRL_LEFT_ON
3910      * @see #META_CTRL_RIGHT_ON
3911      * @see #META_META_ON
3912      * @see #META_META_LEFT_ON
3913      * @see #META_META_RIGHT_ON
3914      * @see #META_CAPS_LOCK_ON
3915      * @see #META_NUM_LOCK_ON
3916      * @see #META_SCROLL_LOCK_ON
3917      * @see #getModifiers
3918      */
3919     public final int getMetaState() {
3920         return mMetaState;
3921     }
3922 
3923     /**
3924      * Returns the state of the modifier keys.
3925      * <p>
3926      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
3927      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
3928      * not considered modifier keys.  Consequently, this function specifically masks out
3929      * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
3930      * </p><p>
3931      * The value returned consists of the meta state (from {@link #getMetaState})
3932      * normalized using {@link #normalizeMetaState(int)} and then masked with
3933      * {@link #getModifierMetaStateMask} so that only valid modifier bits are retained.
3934      * </p>
3935      *
3936      * @return An integer in which each bit set to 1 represents a pressed modifier key.
3937      * @see #getMetaState
3938      */
3939     public final int getModifiers() {
3940         return normalizeMetaState(mMetaState) & META_MODIFIER_MASK;
3941     }
3942 
3943     /**
3944      * Returns the flags for this key event.
3945      *
3946      * @see #FLAG_WOKE_HERE
3947      */
3948     public final int getFlags() {
3949         return mFlags;
3950     }
3951 
3952     // Mask of all modifier key meta states.  Specifically excludes locked keys like caps lock.
3953     private static final int META_MODIFIER_MASK =
3954             META_SHIFT_ON | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON
3955             | META_ALT_ON | META_ALT_LEFT_ON | META_ALT_RIGHT_ON
3956             | META_CTRL_ON | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON
3957             | META_META_ON | META_META_LEFT_ON | META_META_RIGHT_ON
3958             | META_SYM_ON | META_FUNCTION_ON;
3959 
3960     // Mask of all lock key meta states.
3961     private static final int META_LOCK_MASK =
3962             META_CAPS_LOCK_ON | META_NUM_LOCK_ON | META_SCROLL_LOCK_ON;
3963 
3964     // Mask of all valid meta states.
3965     private static final int META_ALL_MASK = META_MODIFIER_MASK | META_LOCK_MASK;
3966 
3967     // Mask of all synthetic meta states that are reserved for API compatibility with
3968     // historical uses in MetaKeyKeyListener.
3969     private static final int META_SYNTHETIC_MASK =
3970             META_CAP_LOCKED | META_ALT_LOCKED | META_SYM_LOCKED | META_SELECTING;
3971 
3972     // Mask of all meta states that are not valid use in specifying a modifier key.
3973     // These bits are known to be used for purposes other than specifying modifiers.
3974     private static final int META_INVALID_MODIFIER_MASK =
3975             META_LOCK_MASK | META_SYNTHETIC_MASK;
3976 
3977     /**
3978      * Gets a mask that includes all valid modifier key meta state bits.
3979      * <p>
3980      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
3981      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
3982      * not considered modifier keys.  Consequently, the mask specifically excludes
3983      * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
3984      * </p>
3985      *
3986      * @return The modifier meta state mask which is a combination of
3987      * {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}, {@link #META_SHIFT_RIGHT_ON},
3988      * {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}, {@link #META_ALT_RIGHT_ON},
3989      * {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}, {@link #META_CTRL_RIGHT_ON},
3990      * {@link #META_META_ON}, {@link #META_META_LEFT_ON}, {@link #META_META_RIGHT_ON},
3991      * {@link #META_SYM_ON}, {@link #META_FUNCTION_ON}.
3992      */
3993     public static int getModifierMetaStateMask() {
3994         return META_MODIFIER_MASK;
3995     }
3996 
3997     /**
3998      * Returns true if this key code is a modifier key.
3999      * <p>
4000      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
4001      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
4002      * not considered modifier keys.  Consequently, this function return false
4003      * for those keys.
4004      * </p>
4005      *
4006      * @return True if the key code is one of
4007      * {@link #KEYCODE_SHIFT_LEFT} {@link #KEYCODE_SHIFT_RIGHT},
4008      * {@link #KEYCODE_ALT_LEFT}, {@link #KEYCODE_ALT_RIGHT},
4009      * {@link #KEYCODE_CTRL_LEFT}, {@link #KEYCODE_CTRL_RIGHT},
4010      * {@link #KEYCODE_META_LEFT}, or {@link #KEYCODE_META_RIGHT},
4011      * {@link #KEYCODE_SYM}, {@link #KEYCODE_NUM}, {@link #KEYCODE_FUNCTION}.
4012      */
4013     public static boolean isModifierKey(int keyCode) {
4014         switch (keyCode) {
4015             case KEYCODE_SHIFT_LEFT:
4016             case KEYCODE_SHIFT_RIGHT:
4017             case KEYCODE_ALT_LEFT:
4018             case KEYCODE_ALT_RIGHT:
4019             case KEYCODE_CTRL_LEFT:
4020             case KEYCODE_CTRL_RIGHT:
4021             case KEYCODE_META_LEFT:
4022             case KEYCODE_META_RIGHT:
4023             case KEYCODE_SYM:
4024             case KEYCODE_NUM:
4025             case KEYCODE_FUNCTION:
4026                 return true;
4027             default:
4028                 return false;
4029         }
4030     }
4031 
4032     /**
4033      * Normalizes the specified meta state.
4034      * <p>
4035      * The meta state is normalized such that if either the left or right modifier meta state
4036      * bits are set then the result will also include the universal bit for that modifier.
4037      * </p><p>
4038      * If the specified meta state contains {@link #META_ALT_LEFT_ON} then
4039      * the result will also contain {@link #META_ALT_ON} in addition to {@link #META_ALT_LEFT_ON}
4040      * and the other bits that were specified in the input.  The same is process is
4041      * performed for shift, control and meta.
4042      * </p><p>
4043      * If the specified meta state contains synthetic meta states defined by
4044      * {@link MetaKeyKeyListener}, then those states are translated here and the original
4045      * synthetic meta states are removed from the result.
4046      * {@link MetaKeyKeyListener#META_CAP_LOCKED} is translated to {@link #META_CAPS_LOCK_ON}.
4047      * {@link MetaKeyKeyListener#META_ALT_LOCKED} is translated to {@link #META_ALT_ON}.
4048      * {@link MetaKeyKeyListener#META_SYM_LOCKED} is translated to {@link #META_SYM_ON}.
4049      * </p><p>
4050      * Undefined meta state bits are removed.
4051      * </p>
4052      *
4053      * @param metaState The meta state.
4054      * @return The normalized meta state.
4055      */
4056     public static int normalizeMetaState(int metaState) {
4057         if ((metaState & (META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON)) != 0) {
4058             metaState |= META_SHIFT_ON;
4059         }
4060         if ((metaState & (META_ALT_LEFT_ON | META_ALT_RIGHT_ON)) != 0) {
4061             metaState |= META_ALT_ON;
4062         }
4063         if ((metaState & (META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON)) != 0) {
4064             metaState |= META_CTRL_ON;
4065         }
4066         if ((metaState & (META_META_LEFT_ON | META_META_RIGHT_ON)) != 0) {
4067             metaState |= META_META_ON;
4068         }
4069         if ((metaState & MetaKeyKeyListener.META_CAP_LOCKED) != 0) {
4070             metaState |= META_CAPS_LOCK_ON;
4071         }
4072         if ((metaState & MetaKeyKeyListener.META_ALT_LOCKED) != 0) {
4073             metaState |= META_ALT_ON;
4074         }
4075         if ((metaState & MetaKeyKeyListener.META_SYM_LOCKED) != 0) {
4076             metaState |= META_SYM_ON;
4077         }
4078         return metaState & META_ALL_MASK;
4079     }
4080 
4081     /**
4082      * Returns true if no modifiers keys are pressed according to the specified meta state.
4083      * <p>
4084      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
4085      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
4086      * not considered modifier keys.  Consequently, this function ignores
4087      * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
4088      * </p><p>
4089      * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}.
4090      * </p>
4091      *
4092      * @param metaState The meta state to consider.
4093      * @return True if no modifier keys are pressed.
4094      * @see #hasNoModifiers()
4095      */
4096     public static boolean metaStateHasNoModifiers(int metaState) {
4097         return (normalizeMetaState(metaState) & META_MODIFIER_MASK) == 0;
4098     }
4099 
4100     /**
4101      * Returns true if only the specified modifier keys are pressed according to
4102      * the specified meta state.  Returns false if a different combination of modifier
4103      * keys are pressed.
4104      * <p>
4105      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
4106      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
4107      * not considered modifier keys.  Consequently, this function ignores
4108      * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
4109      * </p><p>
4110      * If the specified modifier mask includes directional modifiers, such as
4111      * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the
4112      * modifier is pressed on that side.
4113      * If the specified modifier mask includes non-directional modifiers, such as
4114      * {@link #META_SHIFT_ON}, then this method ensures that the modifier
4115      * is pressed on either side.
4116      * If the specified modifier mask includes both directional and non-directional modifiers
4117      * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON},
4118      * then this method throws an illegal argument exception.
4119      * </p>
4120      *
4121      * @param metaState The meta state to consider.
4122      * @param modifiers The meta state of the modifier keys to check.  May be a combination
4123      * of modifier meta states as defined by {@link #getModifierMetaStateMask()}.  May be 0 to
4124      * ensure that no modifier keys are pressed.
4125      * @return True if only the specified modifier keys are pressed.
4126      * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers
4127      * @see #hasModifiers
4128      */
4129     public static boolean metaStateHasModifiers(int metaState, int modifiers) {
4130         // Note: For forward compatibility, we allow the parameter to contain meta states
4131         //       that we do not recognize but we explicitly disallow meta states that
4132         //       are not valid modifiers.
4133         if ((modifiers & META_INVALID_MODIFIER_MASK) != 0) {
4134             throw new IllegalArgumentException("modifiers must not contain "
4135                     + "META_CAPS_LOCK_ON, META_NUM_LOCK_ON, META_SCROLL_LOCK_ON, "
4136                     + "META_CAP_LOCKED, META_ALT_LOCKED, META_SYM_LOCKED, "
4137                     + "or META_SELECTING");
4138         }
4139 
4140         metaState = normalizeMetaState(metaState) & META_MODIFIER_MASK;
4141         metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
4142                 META_SHIFT_ON, META_SHIFT_LEFT_ON, META_SHIFT_RIGHT_ON);
4143         metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
4144                 META_ALT_ON, META_ALT_LEFT_ON, META_ALT_RIGHT_ON);
4145         metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
4146                 META_CTRL_ON, META_CTRL_LEFT_ON, META_CTRL_RIGHT_ON);
4147         metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
4148                 META_META_ON, META_META_LEFT_ON, META_META_RIGHT_ON);
4149         return metaState == modifiers;
4150     }
4151 
4152     private static int metaStateFilterDirectionalModifiers(int metaState,
4153             int modifiers, int basic, int left, int right) {
4154         final boolean wantBasic = (modifiers & basic) != 0;
4155         final int directional = left | right;
4156         final boolean wantLeftOrRight = (modifiers & directional) != 0;
4157 
4158         if (wantBasic) {
4159             if (wantLeftOrRight) {
4160                 throw new IllegalArgumentException("modifiers must not contain "
4161                         + metaStateToString(basic) + " combined with "
4162                         + metaStateToString(left) + " or " + metaStateToString(right));
4163             }
4164             return metaState & ~directional;
4165         } else if (wantLeftOrRight) {
4166             return metaState & ~basic;
4167         } else {
4168             return metaState;
4169         }
4170     }
4171 
4172     /**
4173      * Returns true if no modifier keys are pressed.
4174      * <p>
4175      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
4176      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
4177      * not considered modifier keys.  Consequently, this function ignores
4178      * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
4179      * </p><p>
4180      * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}.
4181      * </p>
4182      *
4183      * @return True if no modifier keys are pressed.
4184      * @see #metaStateHasNoModifiers
4185      */
4186     public final boolean hasNoModifiers() {
4187         return metaStateHasNoModifiers(mMetaState);
4188     }
4189 
4190     /**
4191      * Returns true if only the specified modifiers keys are pressed.
4192      * Returns false if a different combination of modifier keys are pressed.
4193      * <p>
4194      * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
4195      * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
4196      * not considered modifier keys.  Consequently, this function ignores
4197      * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
4198      * </p><p>
4199      * If the specified modifier mask includes directional modifiers, such as
4200      * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the
4201      * modifier is pressed on that side.
4202      * If the specified modifier mask includes non-directional modifiers, such as
4203      * {@link #META_SHIFT_ON}, then this method ensures that the modifier
4204      * is pressed on either side.
4205      * If the specified modifier mask includes both directional and non-directional modifiers
4206      * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON},
4207      * then this method throws an illegal argument exception.
4208      * </p>
4209      *
4210      * @param modifiers The meta state of the modifier keys to check.  May be a combination
4211      * of modifier meta states as defined by {@link #getModifierMetaStateMask()}.  May be 0 to
4212      * ensure that no modifier keys are pressed.
4213      * @return True if only the specified modifier keys are pressed.
4214      * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers
4215      * @see #metaStateHasModifiers
4216      */
4217     public final boolean hasModifiers(int modifiers) {
4218         return metaStateHasModifiers(mMetaState, modifiers);
4219     }
4220 
4221     /**
4222      * <p>Returns the pressed state of the ALT meta key.</p>
4223      *
4224      * @return true if the ALT key is pressed, false otherwise
4225      *
4226      * @see #KEYCODE_ALT_LEFT
4227      * @see #KEYCODE_ALT_RIGHT
4228      * @see #META_ALT_ON
4229      */
4230     public final boolean isAltPressed() {
4231         return (mMetaState & META_ALT_ON) != 0;
4232     }
4233 
4234     /**
4235      * <p>Returns the pressed state of the SHIFT meta key.</p>
4236      *
4237      * @return true if the SHIFT key is pressed, false otherwise
4238      *
4239      * @see #KEYCODE_SHIFT_LEFT
4240      * @see #KEYCODE_SHIFT_RIGHT
4241      * @see #META_SHIFT_ON
4242      */
4243     public final boolean isShiftPressed() {
4244         return (mMetaState & META_SHIFT_ON) != 0;
4245     }
4246 
4247     /**
4248      * <p>Returns the pressed state of the SYM meta key.</p>
4249      *
4250      * @return true if the SYM key is pressed, false otherwise
4251      *
4252      * @see #KEYCODE_SYM
4253      * @see #META_SYM_ON
4254      */
4255     public final boolean isSymPressed() {
4256         return (mMetaState & META_SYM_ON) != 0;
4257     }
4258 
4259     /**
4260      * <p>Returns the pressed state of the CTRL meta key.</p>
4261      *
4262      * @return true if the CTRL key is pressed, false otherwise
4263      *
4264      * @see #KEYCODE_CTRL_LEFT
4265      * @see #KEYCODE_CTRL_RIGHT
4266      * @see #META_CTRL_ON
4267      */
4268     public final boolean isCtrlPressed() {
4269         return (mMetaState & META_CTRL_ON) != 0;
4270     }
4271 
4272     /**
4273      * <p>Returns the pressed state of the META meta key.</p>
4274      *
4275      * @return true if the META key is pressed, false otherwise
4276      *
4277      * @see #KEYCODE_META_LEFT
4278      * @see #KEYCODE_META_RIGHT
4279      * @see #META_META_ON
4280      */
4281     public final boolean isMetaPressed() {
4282         return (mMetaState & META_META_ON) != 0;
4283     }
4284 
4285     /**
4286      * <p>Returns the pressed state of the FUNCTION meta key.</p>
4287      *
4288      * @return true if the FUNCTION key is pressed, false otherwise
4289      *
4290      * @see #KEYCODE_FUNCTION
4291      * @see #META_FUNCTION_ON
4292      */
4293     public final boolean isFunctionPressed() {
4294         return (mMetaState & META_FUNCTION_ON) != 0;
4295     }
4296 
4297     /**
4298      * <p>Returns the locked state of the CAPS LOCK meta key.</p>
4299      *
4300      * @return true if the CAPS LOCK key is on, false otherwise
4301      *
4302      * @see #KEYCODE_CAPS_LOCK
4303      * @see #META_CAPS_LOCK_ON
4304      */
4305     public final boolean isCapsLockOn() {
4306         return (mMetaState & META_CAPS_LOCK_ON) != 0;
4307     }
4308 
4309     /**
4310      * <p>Returns the locked state of the NUM LOCK meta key.</p>
4311      *
4312      * @return true if the NUM LOCK key is on, false otherwise
4313      *
4314      * @see #KEYCODE_NUM_LOCK
4315      * @see #META_NUM_LOCK_ON
4316      */
4317     public final boolean isNumLockOn() {
4318         return (mMetaState & META_NUM_LOCK_ON) != 0;
4319     }
4320 
4321     /**
4322      * <p>Returns the locked state of the SCROLL LOCK meta key.</p>
4323      *
4324      * @return true if the SCROLL LOCK key is on, false otherwise
4325      *
4326      * @see #KEYCODE_SCROLL_LOCK
4327      * @see #META_SCROLL_LOCK_ON
4328      */
4329     public final boolean isScrollLockOn() {
4330         return (mMetaState & META_SCROLL_LOCK_ON) != 0;
4331     }
4332 
4333     /**
4334      * Retrieve the action of this key event.  May be either
4335      * {@link #ACTION_DOWN}, {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
4336      * 
4337      * @return The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
4338      */
4339     public final int getAction() {
4340         return mAction;
4341     }
4342 
4343     /**
4344      * For {@link #ACTION_UP} events, indicates that the event has been
4345      * canceled as per {@link #FLAG_CANCELED}.
4346      */
4347     public final boolean isCanceled() {
4348         return (mFlags&FLAG_CANCELED) != 0;
4349     }
4350     
4351     /**
4352      * Call this during {@link Callback#onKeyDown} to have the system track
4353      * the key through its final up (possibly including a long press).  Note
4354      * that only one key can be tracked at a time -- if another key down
4355      * event is received while a previous one is being tracked, tracking is
4356      * stopped on the previous event.
4357      */
4358     public final void startTracking() {
4359         mFlags |= FLAG_START_TRACKING;
4360     }
4361     
4362     /**
4363      * For {@link #ACTION_UP} events, indicates that the event is still being
4364      * tracked from its initial down event as per
4365      * {@link #FLAG_TRACKING}.
4366      */
4367     public final boolean isTracking() {
4368         return (mFlags&FLAG_TRACKING) != 0;
4369     }
4370     
4371     /**
4372      * For {@link #ACTION_DOWN} events, indicates that the event has been
4373      * canceled as per {@link #FLAG_LONG_PRESS}.
4374      */
4375     public final boolean isLongPress() {
4376         return (mFlags&FLAG_LONG_PRESS) != 0;
4377     }
4378     
4379     /**
4380      * Retrieve the key code of the key event.  This is the physical key that
4381      * was pressed, <em>not</em> the Unicode character.
4382      * 
4383      * @return The key code of the event.
4384      */
4385     public final int getKeyCode() {
4386         return mKeyCode;
4387     }
4388 
4389     /**
4390      * For the special case of a {@link #ACTION_MULTIPLE} event with key
4391      * code of {@link #KEYCODE_UNKNOWN}, this is a raw string of characters
4392      * associated with the event.  In all other cases it is null.
4393      * 
4394      * @return Returns a String of 1 or more characters associated with
4395      * the event.
4396      */
4397     public final String getCharacters() {
4398         return mCharacters;
4399     }
4400     
4401     /**
4402      * Retrieve the hardware key id of this key event.  These values are not
4403      * reliable and vary from device to device.
4404      *
4405      * {@more}
4406      * Mostly this is here for debugging purposes.
4407      */
4408     public final int getScanCode() {
4409         return mScanCode;
4410     }
4411 
4412     /**
4413      * Retrieve the repeat count of the event.  For both key up and key down
4414      * events, this is the number of times the key has repeated with the first
4415      * down starting at 0 and counting up from there.  For multiple key
4416      * events, this is the number of down/up pairs that have occurred.
4417      * 
4418      * @return The number of times the key has repeated.
4419      */
4420     public final int getRepeatCount() {
4421         return mRepeatCount;
4422     }
4423 
4424     /**
4425      * Retrieve the time of the most recent key down event,
4426      * in the {@link android.os.SystemClock#uptimeMillis} time base.  If this
4427      * is a down event, this will be the same as {@link #getEventTime()}.
4428      * Note that when chording keys, this value is the down time of the
4429      * most recently pressed key, which may <em>not</em> be the same physical
4430      * key of this event.
4431      * 
4432      * @return Returns the most recent key down time, in the
4433      * {@link android.os.SystemClock#uptimeMillis} time base
4434      */
4435     public final long getDownTime() {
4436         return mDownTime;
4437     }
4438 
4439     /**
4440      * Retrieve the time this event occurred,
4441      * in the {@link android.os.SystemClock#uptimeMillis} time base.
4442      *
4443      * @return Returns the time this event occurred, 
4444      * in the {@link android.os.SystemClock#uptimeMillis} time base.
4445      */
4446     @Override
4447     public final long getEventTime() {
4448         return mEventTime;
4449     }
4450 
4451     /**
4452      * Retrieve the time this event occurred,
4453      * in the {@link android.os.SystemClock#uptimeMillis} time base but with
4454      * nanosecond (instead of millisecond) precision.
4455      * <p>
4456      * The value is in nanosecond precision but it may not have nanosecond accuracy.
4457      * </p>
4458      *
4459      * @return Returns the time this event occurred,
4460      * in the {@link android.os.SystemClock#uptimeMillis} time base but with
4461      * nanosecond (instead of millisecond) precision.
4462      *
4463      * @hide
4464      */
4465     @Override
4466     public final long getEventTimeNano() {
4467         return mEventTime * 1000000L;
4468     }
4469 
4470     /**
4471      * Renamed to {@link #getDeviceId}.
4472      * 
4473      * @hide
4474      * @deprecated use {@link #getDeviceId()} instead.
4475      */
4476     @Deprecated
4477     public final int getKeyboardDevice() {
4478         return mDeviceId;
4479     }
4480 
4481     /**
4482      * Gets the {@link KeyCharacterMap} associated with the keyboard device.
4483      *
4484      * @return The associated key character map.
4485      * @throws {@link KeyCharacterMap.UnavailableException} if the key character map
4486      * could not be loaded because it was malformed or the default key character map
4487      * is missing from the system.
4488      *
4489      * @see KeyCharacterMap#load
4490      */
4491     public final KeyCharacterMap getKeyCharacterMap() {
4492         return KeyCharacterMap.load(mDeviceId);
4493     }
4494 
4495     /**
4496      * Gets the primary character for this key.
4497      * In other words, the label that is physically printed on it.
4498      *
4499      * @return The display label character, or 0 if none (eg. for non-printing keys).
4500      */
4501     public char getDisplayLabel() {
4502         return getKeyCharacterMap().getDisplayLabel(mKeyCode);
4503     }
4504     
4505     /**
4506      * Gets the Unicode character generated by the specified key and meta
4507      * key state combination.
4508      * <p>
4509      * Returns the Unicode character that the specified key would produce
4510      * when the specified meta bits (see {@link MetaKeyKeyListener})
4511      * were active.
4512      * </p><p>
4513      * Returns 0 if the key is not one that is used to type Unicode
4514      * characters.
4515      * </p><p>
4516      * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the
4517      * key is a "dead key" that should be combined with another to
4518      * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} --
4519      * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}.
4520      * </p>
4521      *
4522      * @return The associated character or combining accent, or 0 if none.
4523      */
4524     public int getUnicodeChar() {
4525         return getUnicodeChar(mMetaState);
4526     }
4527     
4528     /**
4529      * Gets the Unicode character generated by the specified key and meta
4530      * key state combination.
4531      * <p>
4532      * Returns the Unicode character that the specified key would produce
4533      * when the specified meta bits (see {@link MetaKeyKeyListener})
4534      * were active.
4535      * </p><p>
4536      * Returns 0 if the key is not one that is used to type Unicode
4537      * characters.
4538      * </p><p>
4539      * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the
4540      * key is a "dead key" that should be combined with another to
4541      * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} --
4542      * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}.
4543      * </p>
4544      *
4545      * @param metaState The meta key modifier state.
4546      * @return The associated character or combining accent, or 0 if none.
4547      */
4548     public int getUnicodeChar(int metaState) {
4549         return getKeyCharacterMap().get(mKeyCode, metaState);
4550     }
4551     
4552     /**
4553      * Get the character conversion data for a given key code.
4554      *
4555      * @param results A {@link KeyCharacterMap.KeyData} instance that will be
4556      * filled with the results.
4557      * @return True if the key was mapped.  If the key was not mapped, results is not modified.
4558      *
4559      * @deprecated instead use {@link #getDisplayLabel()},
4560      * {@link #getNumber()} or {@link #getUnicodeChar(int)}.
4561      */
4562     @Deprecated
4563     public boolean getKeyData(KeyData results) {
4564         return getKeyCharacterMap().getKeyData(mKeyCode, results);
4565     }
4566     
4567     /**
4568      * Gets the first character in the character array that can be generated
4569      * by the specified key code.
4570      * <p>
4571      * This is a convenience function that returns the same value as
4572      * {@link #getMatch(char[],int) getMatch(chars, 0)}.
4573      * </p>
4574      *
4575      * @param chars The array of matching characters to consider.
4576      * @return The matching associated character, or 0 if none.
4577      */
4578     public char getMatch(char[] chars) {
4579         return getMatch(chars, 0);
4580     }
4581     
4582     /**
4583      * Gets the first character in the character array that can be generated
4584      * by the specified key code.  If there are multiple choices, prefers
4585      * the one that would be generated with the specified meta key modifier state.
4586      *
4587      * @param chars The array of matching characters to consider.
4588      * @param metaState The preferred meta key modifier state.
4589      * @return The matching associated character, or 0 if none.
4590      */
4591     public char getMatch(char[] chars, int metaState) {
4592         return getKeyCharacterMap().getMatch(mKeyCode, chars, metaState);
4593     }
4594     
4595     /**
4596      * Gets the number or symbol associated with the key.
4597      * <p>
4598      * The character value is returned, not the numeric value.
4599      * If the key is not a number, but is a symbol, the symbol is retuned.
4600      * </p><p>
4601      * This method is intended to to support dial pads and other numeric or
4602      * symbolic entry on keyboards where certain keys serve dual function
4603      * as alphabetic and symbolic keys.  This method returns the number
4604      * or symbol associated with the key independent of whether the user
4605      * has pressed the required modifier.
4606      * </p><p>
4607      * For example, on one particular keyboard the keys on the top QWERTY row generate
4608      * numbers when ALT is pressed such that ALT-Q maps to '1'.  So for that keyboard
4609      * when {@link #getNumber} is called with {@link KeyEvent#KEYCODE_Q} it returns '1'
4610      * so that the user can type numbers without pressing ALT when it makes sense.
4611      * </p>
4612      *
4613      * @return The associated numeric or symbolic character, or 0 if none.
4614      */
4615     public char getNumber() {
4616         return getKeyCharacterMap().getNumber(mKeyCode);
4617     }
4618     
4619     /**
4620      * Returns true if this key produces a glyph.
4621      *
4622      * @return True if the key is a printing key.
4623      */
4624     public boolean isPrintingKey() {
4625         return getKeyCharacterMap().isPrintingKey(mKeyCode);
4626     }
4627     
4628     /**
4629      * @deprecated Use {@link #dispatch(Callback, DispatcherState, Object)} instead.
4630      */
4631     @Deprecated
4632     public final boolean dispatch(Callback receiver) {
4633         return dispatch(receiver, null, null);
4634     }
4635     
4636     /**
4637      * Deliver this key event to a {@link Callback} interface.  If this is
4638      * an ACTION_MULTIPLE event and it is not handled, then an attempt will
4639      * be made to deliver a single normal event.
4640      * 
4641      * @param receiver The Callback that will be given the event.
4642      * @param state State information retained across events.
4643      * @param target The target of the dispatch, for use in tracking.
4644      * 
4645      * @return The return value from the Callback method that was called.
4646      */
4647     public final boolean dispatch(Callback receiver, DispatcherState state,
4648             Object target) {
4649         switch (mAction) {
4650             case ACTION_DOWN: {
4651                 mFlags &= ~FLAG_START_TRACKING;
4652                 if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state
4653                         + ": " + this);
4654                 boolean res = receiver.onKeyDown(mKeyCode, this);
4655                 if (state != null) {
4656                     if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) {
4657                         if (DEBUG) Log.v(TAG, "  Start tracking!");
4658                         state.startTracking(this, target);
4659                     } else if (isLongPress() && state.isTracking(this)) {
4660                         try {
4661                             if (receiver.onKeyLongPress(mKeyCode, this)) {
4662                                 if (DEBUG) Log.v(TAG, "  Clear from long press!");
4663                                 state.performedLongPress(this);
4664                                 res = true;
4665                             }
4666                         } catch (AbstractMethodError e) {
4667                         }
4668                     }
4669                 }
4670                 return res;
4671             }
4672             case ACTION_UP:
4673                 if (DEBUG) Log.v(TAG, "Key up to " + target + " in " + state
4674                         + ": " + this);
4675                 if (state != null) {
4676                     state.handleUpEvent(this);
4677                 }
4678                 return receiver.onKeyUp(mKeyCode, this);
4679             case ACTION_MULTIPLE:
4680                 final int count = mRepeatCount;
4681                 final int code = mKeyCode;
4682                 if (receiver.onKeyMultiple(code, count, this)) {
4683                     return true;
4684                 }
4685                 if (code != KeyEvent.KEYCODE_UNKNOWN) {
4686                     mAction = ACTION_DOWN;
4687                     mRepeatCount = 0;
4688                     boolean handled = receiver.onKeyDown(code, this);
4689                     if (handled) {
4690                         mAction = ACTION_UP;
4691                         receiver.onKeyUp(code, this);
4692                     }
4693                     mAction = ACTION_MULTIPLE;
4694                     mRepeatCount = count;
4695                     return handled;
4696                 }
4697                 return false;
4698         }
4699         return false;
4700     }
4701 
4702     /**
4703      * Use with {@link KeyEvent#dispatch(Callback, DispatcherState, Object)}
4704      * for more advanced key dispatching, such as long presses.
4705      */
4706     public static class DispatcherState {
4707         int mDownKeyCode;
4708         Object mDownTarget;
4709         SparseIntArray mActiveLongPresses = new SparseIntArray();
4710         
4711         /**
4712          * Reset back to initial state.
4713          */
4714         public void reset() {
4715             if (DEBUG) Log.v(TAG, "Reset: " + this);
4716             mDownKeyCode = 0;
4717             mDownTarget = null;
4718             mActiveLongPresses.clear();
4719         }
4720         
4721         /**
4722          * Stop any tracking associated with this target.
4723          */
4724         public void reset(Object target) {
4725             if (mDownTarget == target) {
4726                 if (DEBUG) Log.v(TAG, "Reset in " + target + ": " + this);
4727                 mDownKeyCode = 0;
4728                 mDownTarget = null;
4729             }
4730         }
4731         
4732         /**
4733          * Start tracking the key code associated with the given event.  This
4734          * can only be called on a key down.  It will allow you to see any
4735          * long press associated with the key, and will result in
4736          * {@link KeyEvent#isTracking} return true on the long press and up
4737          * events.
4738          * 
4739          * <p>This is only needed if you are directly dispatching events, rather
4740          * than handling them in {@link Callback#onKeyDown}.
4741          */
4742         public void startTracking(KeyEvent event, Object target) {
4743             if (event.getAction() != ACTION_DOWN) {
4744                 throw new IllegalArgumentException(
4745                         "Can only start tracking on a down event");
4746             }
4747             if (DEBUG) Log.v(TAG, "Start trackingt in " + target + ": " + this);
4748             mDownKeyCode = event.getKeyCode();
4749             mDownTarget = target;
4750         }
4751         
4752         /**
4753          * Return true if the key event is for a key code that is currently
4754          * being tracked by the dispatcher.
4755          */
4756         public boolean isTracking(KeyEvent event) {
4757             return mDownKeyCode == event.getKeyCode();
4758         }
4759         
4760         /**
4761          * Keep track of the given event's key code as having performed an
4762          * action with a long press, so no action should occur on the up.
4763          * <p>This is only needed if you are directly dispatching events, rather
4764          * than handling them in {@link Callback#onKeyLongPress}.
4765          */
4766         public void performedLongPress(KeyEvent event) {
4767             mActiveLongPresses.put(event.getKeyCode(), 1);
4768         }
4769         
4770         /**
4771          * Handle key up event to stop tracking.  This resets the dispatcher state,
4772          * and updates the key event state based on it.
4773          * <p>This is only needed if you are directly dispatching events, rather
4774          * than handling them in {@link Callback#onKeyUp}.
4775          */
4776         public void handleUpEvent(KeyEvent event) {
4777             final int keyCode = event.getKeyCode();
4778             if (DEBUG) Log.v(TAG, "Handle key up " + event + ": " + this);
4779             int index = mActiveLongPresses.indexOfKey(keyCode);
4780             if (index >= 0) {
4781                 if (DEBUG) Log.v(TAG, "  Index: " + index);
4782                 event.mFlags |= FLAG_CANCELED | FLAG_CANCELED_LONG_PRESS;
4783                 mActiveLongPresses.removeAt(index);
4784             }
4785             if (mDownKeyCode == keyCode) {
4786                 if (DEBUG) Log.v(TAG, "  Tracking!");
4787                 event.mFlags |= FLAG_TRACKING;
4788                 mDownKeyCode = 0;
4789                 mDownTarget = null;
4790             }
4791         }
4792     }
4793 
4794     @Override
4795     public String toString() {
4796         StringBuilder msg = new StringBuilder();
4797         msg.append("KeyEvent { action=").append(actionToString(mAction));
4798         msg.append(", keyCode=").append(keyCodeToString(mKeyCode));
4799         msg.append(", scanCode=").append(mScanCode);
4800         if (mCharacters != null) {
4801             msg.append(", characters=\"").append(mCharacters).append("\"");
4802         }
4803         msg.append(", metaState=").append(metaStateToString(mMetaState));
4804         msg.append(", flags=0x").append(Integer.toHexString(mFlags));
4805         msg.append(", repeatCount=").append(mRepeatCount);
4806         msg.append(", eventTime=").append(mEventTime);
4807         msg.append(", downTime=").append(mDownTime);
4808         msg.append(", deviceId=").append(mDeviceId);
4809         msg.append(", source=0x").append(Integer.toHexString(mSource));
4810         msg.append(" }");
4811         return msg.toString();
4812     }
4813 
4814     /**
4815      * Returns a string that represents the symbolic name of the specified action
4816      * such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown.
4817      *
4818      * @param action The action.
4819      * @return The symbolic name of the specified action.
4820      * @hide
4821      */
4822     public static String actionToString(int action) {
4823         switch (action) {
4824             case ACTION_DOWN:
4825                 return "ACTION_DOWN";
4826             case ACTION_UP:
4827                 return "ACTION_UP";
4828             case ACTION_MULTIPLE:
4829                 return "ACTION_MULTIPLE";
4830             default:
4831                 return Integer.toString(action);
4832         }
4833     }
4834 
4835     /**
4836      * Returns a string that represents the symbolic name of the specified keycode
4837      * such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant
4838      * such as "1001" if unknown.
4839      *
4840      * @param keyCode The key code.
4841      * @return The symbolic name of the specified keycode.
4842      *
4843      * @see KeyCharacterMap#getDisplayLabel
4844      */
4845     public static String keyCodeToString(int keyCode) {
4846         String symbolicName = KEYCODE_SYMBOLIC_NAMES.get(keyCode);
4847         return symbolicName != null ? symbolicName : Integer.toString(keyCode);
4848     }
4849 
4850     /**
4851      * Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent
4852      * numeric constant such as "1001".
4853      *
4854      * @param symbolicName The symbolic name of the keycode.
4855      * @return The keycode or {@link #KEYCODE_UNKNOWN} if not found.
4856      * @see #keycodeToString
4857      */
4858     public static int keyCodeFromString(String symbolicName) {
4859         if (symbolicName == null) {
4860             throw new IllegalArgumentException("symbolicName must not be null");
4861         }
4862 
4863         final int count = KEYCODE_SYMBOLIC_NAMES.size();
4864         for (int i = 0; i < count; i++) {
4865             if (symbolicName.equals(KEYCODE_SYMBOLIC_NAMES.valueAt(i))) {
4866                 return i;
4867             }
4868         }
4869 
4870         try {
4871             return Integer.parseInt(symbolicName, 10);
4872         } catch (NumberFormatException ex) {
4873             return KEYCODE_UNKNOWN;
4874         }
4875     }
4876 
4877     /**
4878      * Returns a string that represents the symbolic name of the specified combined meta
4879      * key modifier state flags such as "0", "META_SHIFT_ON",
4880      * "META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000"
4881      * if unknown.
4882      *
4883      * @param metaState The meta state.
4884      * @return The symbolic name of the specified combined meta state flags.
4885      * @hide
4886      */
4887     public static String metaStateToString(int metaState) {
4888         if (metaState == 0) {
4889             return "0";
4890         }
4891         StringBuilder result = null;
4892         int i = 0;
4893         while (metaState != 0) {
4894             final boolean isSet = (metaState & 1) != 0;
4895             metaState >>>= 1; // unsigned shift!
4896             if (isSet) {
4897                 final String name = META_SYMBOLIC_NAMES[i];
4898                 if (result == null) {
4899                     if (metaState == 0) {
4900                         return name;
4901                     }
4902                     result = new StringBuilder(name);
4903                 } else {
4904                     result.append('|');
4905                     result.append(name);
4906                 }
4907             }
4908             i += 1;
4909         }
4910         return result.toString();
4911     }
4912 
4913     public static final Parcelable.Creator<KeyEvent> CREATOR
4914             = new Parcelable.Creator<KeyEvent>() {
4915         public KeyEvent createFromParcel(Parcel in) {
4916             in.readInt(); // skip token, we already know this is a KeyEvent
4917             return KeyEvent.createFromParcelBody(in);
4918         }
4919 
4920         public KeyEvent[] newArray(int size) {
4921             return new KeyEvent[size];
4922         }
4923     };
4924     
4925     /** @hide */
4926     public static KeyEvent createFromParcelBody(Parcel in) {
4927         return new KeyEvent(in);
4928     }
4929     
4930     private KeyEvent(Parcel in) {
4931         mDeviceId = in.readInt();
4932         mSource = in.readInt();
4933         mAction = in.readInt();
4934         mKeyCode = in.readInt();
4935         mRepeatCount = in.readInt();
4936         mMetaState = in.readInt();
4937         mScanCode = in.readInt();
4938         mFlags = in.readInt();
4939         mDownTime = in.readLong();
4940         mEventTime = in.readLong();
4941     }
4942 
4943     public void writeToParcel(Parcel out, int flags) {
4944         out.writeInt(PARCEL_TOKEN_KEY_EVENT);
4945 
4946         out.writeInt(mDeviceId);
4947         out.writeInt(mSource);
4948         out.writeInt(mAction);
4949         out.writeInt(mKeyCode);
4950         out.writeInt(mRepeatCount);
4951         out.writeInt(mMetaState);
4952         out.writeInt(mScanCode);
4953         out.writeInt(mFlags);
4954         out.writeLong(mDownTime);
4955         out.writeLong(mEventTime);
4956     }
4957 
4958     private native boolean native_isSystemKey(int keyCode);
4959     private native boolean native_hasDefaultAction(int keyCode);
4960 }
底层实现

 

posted @ 2015-01-14 11:15  狐狸已化妖  阅读(14682)  评论(0编辑  收藏  举报