1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.car.keventreader; 17 18 import android.os.Parcel; 19 import android.os.Parcelable; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 24 public final class KeypressEvent implements Parcelable { 25 private static final Map<Integer, String> KEYCODE_NAME_MAP = new HashMap<Integer, String>() {{ 26 put(0,"RESERVED"); 27 put(1,"ESC"); 28 put(2,"1"); 29 put(3,"2"); 30 put(4,"3"); 31 put(5,"4"); 32 put(6,"5"); 33 put(7,"6"); 34 put(8,"7"); 35 put(9,"8"); 36 put(10,"9"); 37 put(11,"0"); 38 put(12,"MINUS"); 39 put(13,"EQUAL"); 40 put(14,"BACKSPACE"); 41 put(15,"TAB"); 42 put(16,"Q"); 43 put(17,"W"); 44 put(18,"E"); 45 put(19,"R"); 46 put(20,"T"); 47 put(21,"Y"); 48 put(22,"U"); 49 put(23,"I"); 50 put(24,"O"); 51 put(25,"P"); 52 put(26,"LEFTBRACE"); 53 put(27,"RIGHTBRACE"); 54 put(28,"ENTER"); 55 put(29,"LEFTCTRL"); 56 put(30,"A"); 57 put(31,"S"); 58 put(32,"D"); 59 put(33,"F"); 60 put(34,"G"); 61 put(35,"H"); 62 put(36,"J"); 63 put(37,"K"); 64 put(38,"L"); 65 put(39,"SEMICOLON"); 66 put(40,"APOSTROPHE"); 67 put(41,"GRAVE"); 68 put(42,"LEFTSHIFT"); 69 put(43,"BACKSLASH"); 70 put(44,"Z"); 71 put(45,"X"); 72 put(46,"C"); 73 put(47,"V"); 74 put(48,"B"); 75 put(49,"N"); 76 put(50,"M"); 77 put(51,"COMMA"); 78 put(52,"DOT"); 79 put(53,"SLASH"); 80 put(54,"RIGHTSHIFT"); 81 put(55,"KPASTERISK"); 82 put(56,"LEFTALT"); 83 put(57,"SPACE"); 84 put(58,"CAPSLOCK"); 85 put(59,"F1"); 86 put(60,"F2"); 87 put(61,"F3"); 88 put(62,"F4"); 89 put(63,"F5"); 90 put(64,"F6"); 91 put(65,"F7"); 92 put(66,"F8"); 93 put(67,"F9"); 94 put(68,"F10"); 95 put(69,"NUMLOCK"); 96 put(70,"SCROLLLOCK"); 97 put(71,"KP7"); 98 put(72,"KP8"); 99 put(73,"KP9"); 100 put(74,"KPMINUS"); 101 put(75,"KP4"); 102 put(76,"KP5"); 103 put(77,"KP6"); 104 put(78,"KPPLUS"); 105 put(79,"KP1"); 106 put(80,"KP2"); 107 put(81,"KP3"); 108 put(82,"KP0"); 109 put(83,"KPDOT"); 110 put(85,"ZENKAKUHANKAKU"); 111 put(86,"102ND"); 112 put(87,"F11"); 113 put(88,"F12"); 114 put(89,"RO"); 115 put(90,"KATAKANA"); 116 put(91,"HIRAGANA"); 117 put(92,"HENKAN"); 118 put(93,"KATAKANAHIRAGANA"); 119 put(94,"MUHENKAN"); 120 put(95,"KPJPCOMMA"); 121 put(96,"KPENTER"); 122 put(97,"RIGHTCTRL"); 123 put(98,"KPSLASH"); 124 put(99,"SYSRQ"); 125 put(100,"RIGHTALT"); 126 put(101,"LINEFEED"); 127 put(102,"HOME"); 128 put(103,"UP"); 129 put(104,"PAGEUP"); 130 put(105,"LEFT"); 131 put(106,"RIGHT"); 132 put(107,"END"); 133 put(108,"DOWN"); 134 put(109,"PAGEDOWN"); 135 put(110,"INSERT"); 136 put(111,"DELETE"); 137 put(112,"MACRO"); 138 put(113,"MUTE"); 139 put(114,"VOLUMEDOWN"); 140 put(115,"VOLUMEUP"); 141 put(116,"POWER"); 142 put(117,"KPEQUAL"); 143 put(118,"KPPLUSMINUS"); 144 put(119,"PAUSE"); 145 put(120,"SCALE"); 146 put(121,"KPCOMMA"); 147 put(122,"HANGEUL"); 148 put(123,"HANJA"); 149 put(124,"YEN"); 150 put(125,"LEFTMETA"); 151 put(126,"RIGHTMETA"); 152 put(127,"COMPOSE"); 153 put(128,"STOP"); 154 put(129,"AGAIN"); 155 put(130,"PROPS"); 156 put(131,"UNDO"); 157 put(132,"FRONT"); 158 put(133,"COPY"); 159 put(134,"OPEN"); 160 put(135,"PASTE"); 161 put(136,"FIND"); 162 put(137,"CUT"); 163 put(138,"HELP"); 164 put(139,"MENU"); 165 put(140,"CALC"); 166 put(141,"SETUP"); 167 put(142,"SLEEP"); 168 put(143,"WAKEUP"); 169 put(144,"FILE"); 170 put(145,"SENDFILE"); 171 put(146,"DELETEFILE"); 172 put(147,"XFER"); 173 put(148,"PROG1"); 174 put(149,"PROG2"); 175 put(150,"WWW"); 176 put(151,"MSDOS"); 177 put(152,"SCREENLOCK"); 178 put(153,"ROTATE_DISPLAY"); 179 put(154,"CYCLEWINDOWS"); 180 put(155,"MAIL"); 181 put(156,"BOOKMARKS"); 182 put(157,"COMPUTER"); 183 put(158,"BACK"); 184 put(159,"FORWARD"); 185 put(160,"CLOSECD"); 186 put(161,"EJECTCD"); 187 put(162,"EJECTCLOSECD"); 188 put(163,"NEXTSONG"); 189 put(164,"PLAYPAUSE"); 190 put(165,"PREVIOUSSONG"); 191 put(166,"STOPCD"); 192 put(167,"RECORD"); 193 put(168,"REWIND"); 194 put(169,"PHONE"); 195 put(170,"ISO"); 196 put(171,"CONFIG"); 197 put(172,"HOMEPAGE"); 198 put(173,"REFRESH"); 199 put(174,"EXIT"); 200 put(175,"MOVE"); 201 put(176,"EDIT"); 202 put(177,"SCROLLUP"); 203 put(178,"SCROLLDOWN"); 204 put(179,"KPLEFTPAREN"); 205 put(180,"KPRIGHTPAREN"); 206 put(181,"NEW"); 207 put(182,"REDO"); 208 put(183,"F13"); 209 put(184,"F14"); 210 put(185,"F15"); 211 put(186,"F16"); 212 put(187,"F17"); 213 put(188,"F18"); 214 put(189,"F19"); 215 put(190,"F20"); 216 put(191,"F21"); 217 put(192,"F22"); 218 put(193,"F23"); 219 put(194,"F24"); 220 put(200,"PLAYCD"); 221 put(201,"PAUSECD"); 222 put(202,"PROG3"); 223 put(203,"PROG4"); 224 put(204,"DASHBOARD"); 225 put(205,"SUSPEND"); 226 put(206,"CLOSE"); 227 put(207,"PLAY"); 228 put(208,"FASTFORWARD"); 229 put(209,"BASSBOOST"); 230 put(210,"PRINT"); 231 put(211,"HP"); 232 put(212,"CAMERA"); 233 put(213,"SOUND"); 234 put(214,"QUESTION"); 235 put(215,"EMAIL"); 236 put(216,"CHAT"); 237 put(217,"SEARCH"); 238 put(218,"CONNECT"); 239 put(219,"FINANCE"); 240 put(220,"SPORT"); 241 put(221,"SHOP"); 242 put(222,"ALTERASE"); 243 put(223,"CANCEL"); 244 put(224,"BRIGHTNESSDOWN"); 245 put(225,"BRIGHTNESSUP"); 246 put(226,"MEDIA"); 247 put(227,"SWITCHVIDEOMODE"); 248 put(228,"KBDILLUMTOGGLE"); 249 put(229,"KBDILLUMDOWN"); 250 put(230,"KBDILLUMUP"); 251 put(231,"SEND"); 252 put(232,"REPLY"); 253 put(233,"FORWARDMAIL"); 254 put(234,"SAVE"); 255 put(235,"DOCUMENTS"); 256 put(236,"BATTERY"); 257 put(237,"BLUETOOTH"); 258 put(238,"WLAN"); 259 put(239,"UWB"); 260 put(240,"UNKNOWN"); 261 put(241,"VIDEO_NEXT"); 262 put(242,"VIDEO_PREV"); 263 put(243,"BRIGHTNESS_CYCLE"); 264 put(244,"BRIGHTNESS_AUTO"); 265 put(245,"DISPLAY_OFF"); 266 put(246,"WWAN"); 267 put(247,"RFKILL"); 268 put(248,"MICMUTE"); 269 put(0x160,"OK"); 270 put(0x161,"SELECT"); 271 put(0x162,"GOTO"); 272 put(0x163,"CLEAR"); 273 put(0x164,"POWER2"); 274 put(0x165,"OPTION"); 275 put(0x166,"INFO"); 276 put(0x167,"TIME"); 277 put(0x168,"VENDOR"); 278 put(0x169,"ARCHIVE"); 279 put(0x16a,"PROGRAM"); 280 put(0x16b,"CHANNEL"); 281 put(0x16c,"FAVORITES"); 282 put(0x16d,"EPG"); 283 put(0x16e,"PVR"); 284 put(0x16f,"MHP"); 285 put(0x170,"LANGUAGE"); 286 put(0x171,"TITLE"); 287 put(0x172,"SUBTITLE"); 288 put(0x173,"ANGLE"); 289 put(0x174,"ZOOM"); 290 put(0x175,"MODE"); 291 put(0x176,"KEYBOARD"); 292 put(0x177,"SCREEN"); 293 put(0x178,"PC"); 294 put(0x179,"TV"); 295 put(0x17a,"TV2"); 296 put(0x17b,"VCR"); 297 put(0x17c,"VCR2"); 298 put(0x17d,"SAT"); 299 put(0x17e,"SAT2"); 300 put(0x17f,"CD"); 301 put(0x180,"TAPE"); 302 put(0x181,"RADIO"); 303 put(0x182,"TUNER"); 304 put(0x183,"PLAYER"); 305 put(0x184,"TEXT"); 306 put(0x185,"DVD"); 307 put(0x186,"AUX"); 308 put(0x187,"MP3"); 309 put(0x188,"AUDIO"); 310 put(0x189,"VIDEO"); 311 put(0x18a,"DIRECTORY"); 312 put(0x18b,"LIST"); 313 put(0x18c,"MEMO"); 314 put(0x18d,"CALENDAR"); 315 put(0x18e,"RED"); 316 put(0x18f,"GREEN"); 317 put(0x190,"YELLOW"); 318 put(0x191,"BLUE"); 319 put(0x192,"CHANNELUP"); 320 put(0x193,"CHANNELDOWN"); 321 put(0x194,"FIRST"); 322 put(0x195,"LAST"); 323 put(0x196,"AB"); 324 put(0x197,"NEXT"); 325 put(0x198,"RESTART"); 326 put(0x199,"SLOW"); 327 put(0x19a,"SHUFFLE"); 328 put(0x19b,"BREAK"); 329 put(0x19c,"PREVIOUS"); 330 put(0x19d,"DIGITS"); 331 put(0x19e,"TEEN"); 332 put(0x19f,"TWEN"); 333 put(0x1a0,"VIDEOPHONE"); 334 put(0x1a1,"GAMES"); 335 put(0x1a2,"ZOOMIN"); 336 put(0x1a3,"ZOOMOUT"); 337 put(0x1a4,"ZOOMRESET"); 338 put(0x1a5,"WORDPROCESSOR"); 339 put(0x1a6,"EDITOR"); 340 put(0x1a7,"SPREADSHEET"); 341 put(0x1a8,"GRAPHICSEDITOR"); 342 put(0x1a9,"PRESENTATION"); 343 put(0x1aa,"DATABASE"); 344 put(0x1ab,"NEWS"); 345 put(0x1ac,"VOICEMAIL"); 346 put(0x1ad,"ADDRESSBOOK"); 347 put(0x1ae,"MESSENGER"); 348 put(0x1af,"DISPLAYTOGGLE"); 349 put(0x1b0,"SPELLCHECK"); 350 put(0x1b1,"LOGOFF"); 351 put(0x1b2,"DOLLAR"); 352 put(0x1b3,"EURO"); 353 put(0x1b4,"FRAMEBACK"); 354 put(0x1b5,"FRAMEFORWARD"); 355 put(0x1b6,"CONTEXT_MENU"); 356 put(0x1b7,"MEDIA_REPEAT"); 357 put(0x1b8,"10CHANNELSUP"); 358 put(0x1b9,"10CHANNELSDOWN"); 359 put(0x1ba,"IMAGES"); 360 put(0x1c0,"DEL_EOL"); 361 put(0x1c1,"DEL_EOS"); 362 put(0x1c2,"INS_LINE"); 363 put(0x1c3,"DEL_LINE"); 364 put(0x1d0,"FN"); 365 put(0x1d1,"FN_ESC"); 366 put(0x1d2,"FN_F1"); 367 put(0x1d3,"FN_F2"); 368 put(0x1d4,"FN_F3"); 369 put(0x1d5,"FN_F4"); 370 put(0x1d6,"FN_F5"); 371 put(0x1d7,"FN_F6"); 372 put(0x1d8,"FN_F7"); 373 put(0x1d9,"FN_F8"); 374 put(0x1da,"FN_F9"); 375 put(0x1db,"FN_F10"); 376 put(0x1dc,"FN_F11"); 377 put(0x1dd,"FN_F12"); 378 put(0x1de,"FN_1"); 379 put(0x1df,"FN_2"); 380 put(0x1e0,"FN_D"); 381 put(0x1e1,"FN_E"); 382 put(0x1e2,"FN_F"); 383 put(0x1e3,"FN_S"); 384 put(0x1e4,"FN_B"); 385 put(0x1f1,"BRL_DOT1"); 386 put(0x1f2,"BRL_DOT2"); 387 put(0x1f3,"BRL_DOT3"); 388 put(0x1f4,"BRL_DOT4"); 389 put(0x1f5,"BRL_DOT5"); 390 put(0x1f6,"BRL_DOT6"); 391 put(0x1f7,"BRL_DOT7"); 392 put(0x1f8,"BRL_DOT8"); 393 put(0x1f9,"BRL_DOT9"); 394 put(0x1fa,"BRL_DOT10"); 395 put(0x200,"NUMERIC_0"); 396 put(0x201,"NUMERIC_1"); 397 put(0x202,"NUMERIC_2"); 398 put(0x203,"NUMERIC_3"); 399 put(0x204,"NUMERIC_4"); 400 put(0x205,"NUMERIC_5"); 401 put(0x206,"NUMERIC_6"); 402 put(0x207,"NUMERIC_7"); 403 put(0x208,"NUMERIC_8"); 404 put(0x209,"NUMERIC_9"); 405 put(0x20a,"NUMERIC_STAR"); 406 put(0x20b,"NUMERIC_POUND"); 407 put(0x20c,"NUMERIC_A"); 408 put(0x20d,"NUMERIC_B"); 409 put(0x20e,"NUMERIC_C"); 410 put(0x20f,"NUMERIC_D"); 411 put(0x210,"CAMERA_FOCUS"); 412 put(0x211,"WPS_BUTTON"); 413 put(0x212,"TOUCHPAD_TOGGLE"); 414 put(0x213,"TOUCHPAD_ON"); 415 put(0x214,"TOUCHPAD_OFF"); 416 put(0x215,"CAMERA_ZOOMIN"); 417 put(0x216,"CAMERA_ZOOMOUT"); 418 put(0x217,"CAMERA_UP"); 419 put(0x218,"CAMERA_DOWN"); 420 put(0x219,"CAMERA_LEFT"); 421 put(0x21a,"CAMERA_RIGHT"); 422 put(0x21b,"ATTENDANT_ON"); 423 put(0x21c,"ATTENDANT_OFF"); 424 put(0x21d,"ATTENDANT_TOGGLE"); 425 put(0x21e,"LIGHTS_TOGGLE"); 426 put(0x230,"ALS_TOGGLE"); 427 put(0x240,"BUTTONCONFIG"); 428 put(0x241,"TASKMANAGER"); 429 put(0x242,"JOURNAL"); 430 put(0x243,"CONTROLPANEL"); 431 put(0x244,"APPSELECT"); 432 put(0x245,"SCREENSAVER"); 433 put(0x246,"VOICECOMMAND"); 434 put(0x247,"ASSISTANT"); 435 put(0x250,"BRIGHTNESS_MIN"); 436 put(0x251,"BRIGHTNESS_MAX"); 437 put(0x260,"KBDINPUTASSIST_PREV"); 438 put(0x261,"KBDINPUTASSIST_NEXT"); 439 put(0x262,"KBDINPUTASSIST_PREVGROUP"); 440 put(0x263,"KBDINPUTASSIST_NEXTGROUP"); 441 put(0x264,"KBDINPUTASSIST_ACCEPT"); 442 put(0x265,"KBDINPUTASSIST_CANCEL"); 443 put(0x266,"RIGHT_UP"); 444 put(0x267,"RIGHT_DOWN"); 445 put(0x268,"LEFT_UP"); 446 put(0x269,"LEFT_DOWN"); 447 put(0x26a,"ROOT_MENU"); 448 put(0x26b,"MEDIA_TOP_MENU"); 449 put(0x26c,"NUMERIC_11"); 450 put(0x26d,"NUMERIC_12"); 451 put(0x26e,"AUDIO_DESC"); 452 put(0x26f,"3D_MODE"); 453 put(0x270,"NEXT_FAVORITE"); 454 put(0x271,"STOP_RECORD"); 455 put(0x272,"PAUSE_RECORD"); 456 put(0x273,"VOD"); 457 put(0x274,"UNMUTE"); 458 put(0x275,"FASTREVERSE"); 459 put(0x276,"SLOWREVERSE"); 460 put(0x277,"DATA"); 461 put(0x278,"ONSCREEN_KEYBOARD"); 462 put(113,"MIN_INTERESTING"); 463 put(0x2ff,"MAX"); 464 put(0x100,"MISC"); 465 put(0x100,"0"); 466 put(0x101,"1"); 467 put(0x102,"2"); 468 put(0x103,"3"); 469 put(0x104,"4"); 470 put(0x105,"5"); 471 put(0x106,"6"); 472 put(0x107,"7"); 473 put(0x108,"8"); 474 put(0x109,"9"); 475 put(0x110,"MOUSE"); 476 put(0x110,"LEFT"); 477 put(0x111,"RIGHT"); 478 put(0x112,"MIDDLE"); 479 put(0x113,"SIDE"); 480 put(0x114,"EXTRA"); 481 put(0x115,"FORWARD"); 482 put(0x116,"BACK"); 483 put(0x117,"TASK"); 484 put(0x120,"JOYSTICK"); 485 put(0x120,"TRIGGER"); 486 put(0x121,"THUMB"); 487 put(0x122,"THUMB2"); 488 put(0x123,"TOP"); 489 put(0x124,"TOP2"); 490 put(0x125,"PINKIE"); 491 put(0x126,"BASE"); 492 put(0x127,"BASE2"); 493 put(0x128,"BASE3"); 494 put(0x129,"BASE4"); 495 put(0x12a,"BASE5"); 496 put(0x12b,"BASE6"); 497 put(0x12f,"DEAD"); 498 put(0x130,"GAMEPAD"); 499 put(0x130,"SOUTH"); 500 put(0x131,"EAST"); 501 put(0x132,"C"); 502 put(0x133,"NORTH"); 503 put(0x134,"WEST"); 504 put(0x135,"Z"); 505 put(0x136,"TL"); 506 put(0x137,"TR"); 507 put(0x138,"TL2"); 508 put(0x139,"TR2"); 509 put(0x13a,"SELECT"); 510 put(0x13b,"START"); 511 put(0x13c,"MODE"); 512 put(0x13d,"THUMBL"); 513 put(0x13e,"THUMBR"); 514 put(0x140,"DIGI"); 515 put(0x140,"TOOL_PEN"); 516 put(0x141,"TOOL_RUBBER"); 517 put(0x142,"TOOL_BRUSH"); 518 put(0x143,"TOOL_PENCIL"); 519 put(0x144,"TOOL_AIRBRUSH"); 520 put(0x145,"TOOL_FINGER"); 521 put(0x146,"TOOL_MOUSE"); 522 put(0x147,"TOOL_LENS"); 523 put(0x148,"TOOL_QUINTTAP"); 524 put(0x149,"STYLUS3"); 525 put(0x14a,"TOUCH"); 526 put(0x14b,"STYLUS"); 527 put(0x14c,"STYLUS2"); 528 put(0x14d,"TOOL_DOUBLETAP"); 529 put(0x14e,"TOOL_TRIPLETAP"); 530 put(0x14f,"TOOL_QUADTAP"); 531 put(0x150,"WHEEL"); 532 put(0x150,"GEAR_DOWN"); 533 put(0x151,"GEAR_UP"); 534 put(0x220,"DPAD_UP"); 535 put(0x221,"DPAD_DOWN"); 536 put(0x222,"DPAD_LEFT"); 537 put(0x223,"DPAD_RIGHT"); 538 put(0x2c0,"TRIGGER_HAPPY"); 539 put(0x2c0,"TRIGGER_HAPPY1"); 540 put(0x2c1,"TRIGGER_HAPPY2"); 541 put(0x2c2,"TRIGGER_HAPPY3"); 542 put(0x2c3,"TRIGGER_HAPPY4"); 543 put(0x2c4,"TRIGGER_HAPPY5"); 544 put(0x2c5,"TRIGGER_HAPPY6"); 545 put(0x2c6,"TRIGGER_HAPPY7"); 546 put(0x2c7,"TRIGGER_HAPPY8"); 547 put(0x2c8,"TRIGGER_HAPPY9"); 548 put(0x2c9,"TRIGGER_HAPPY10"); 549 put(0x2ca,"TRIGGER_HAPPY11"); 550 put(0x2cb,"TRIGGER_HAPPY12"); 551 put(0x2cc,"TRIGGER_HAPPY13"); 552 put(0x2cd,"TRIGGER_HAPPY14"); 553 put(0x2ce,"TRIGGER_HAPPY15"); 554 put(0x2cf,"TRIGGER_HAPPY16"); 555 put(0x2d0,"TRIGGER_HAPPY17"); 556 put(0x2d1,"TRIGGER_HAPPY18"); 557 put(0x2d2,"TRIGGER_HAPPY19"); 558 put(0x2d3,"TRIGGER_HAPPY20"); 559 put(0x2d4,"TRIGGER_HAPPY21"); 560 put(0x2d5,"TRIGGER_HAPPY22"); 561 put(0x2d6,"TRIGGER_HAPPY23"); 562 put(0x2d7,"TRIGGER_HAPPY24"); 563 put(0x2d8,"TRIGGER_HAPPY25"); 564 put(0x2d9,"TRIGGER_HAPPY26"); 565 put(0x2da,"TRIGGER_HAPPY27"); 566 put(0x2db,"TRIGGER_HAPPY28"); 567 put(0x2dc,"TRIGGER_HAPPY29"); 568 put(0x2dd,"TRIGGER_HAPPY30"); 569 put(0x2de,"TRIGGER_HAPPY31"); 570 put(0x2df,"TRIGGER_HAPPY32"); 571 put(0x2e0,"TRIGGER_HAPPY33"); 572 put(0x2e1,"TRIGGER_HAPPY34"); 573 put(0x2e2,"TRIGGER_HAPPY35"); 574 put(0x2e3,"TRIGGER_HAPPY36"); 575 put(0x2e4,"TRIGGER_HAPPY37"); 576 put(0x2e5,"TRIGGER_HAPPY38"); 577 put(0x2e6,"TRIGGER_HAPPY39"); 578 put(0x2e7,"TRIGGER_HAPPY40"); 579 }}; 580 581 public final String source; 582 public final int keycode; 583 public final boolean isKeydown; 584 585 public static final Parcelable.Creator<KeypressEvent> CREATOR = 586 new Parcelable.Creator<KeypressEvent>() { 587 public KeypressEvent createFromParcel(Parcel in) { 588 return new KeypressEvent(in); 589 } 590 591 public KeypressEvent[] newArray(int size) { 592 return new KeypressEvent[size]; 593 } 594 }; 595 KeypressEvent(Parcel in)596 public KeypressEvent(Parcel in) { 597 source = in.readString(); 598 keycode = in.readInt(); 599 isKeydown = (in.readInt() != 0); 600 } 601 602 @Override describeContents()603 public int describeContents() { 604 return 0; 605 } 606 607 @Override writeToParcel(Parcel dest, int flags)608 public void writeToParcel(Parcel dest, int flags) { 609 dest.writeString(source); 610 dest.writeInt(keycode); 611 dest.writeInt(isKeydown ? 1 : 0); 612 } 613 614 @Override equals(Object o)615 public boolean equals(Object o) { 616 if (o instanceof KeypressEvent) { 617 KeypressEvent other = (KeypressEvent)o; 618 return other.source.equals(source) && 619 other.keycode == keycode && 620 other.isKeydown == isKeydown; 621 } 622 return false; 623 } 624 625 @Override toString()626 public String toString() { 627 return"Event{source = " + source + ", keycode = " + keycode + 628 ", isKeydown = " + isKeydown + "}"; 629 } 630 keycodeToString()631 public String keycodeToString() { 632 return keycodeToString(keycode); 633 } 634 635 /** 636 * Translates a key code from keventreader into a string. 637 * @param keycode Key code from a keventreader KeypressEvent. 638 * @return String String label corresponding to keycode, if available. If not, String with 639 * hexidecimal representation of keycode. 640 */ keycodeToString(int keycode)641 public static String keycodeToString(int keycode) { 642 String ret = KEYCODE_NAME_MAP.get(keycode); 643 return ret != null ? ret : "0x" + Integer.toHexString(keycode); 644 } 645 } 646