OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Data in this file was created by referencing: | 5 // Data in this file was created by referencing: |
6 // USB HID Usage Tables (v1.11) 27 June 2001 | 6 // USB HID Usage Tables (v1.11) 27 June 2001 |
7 // HIToolbox/Events.h (Mac) | 7 // HIToolbox/Events.h (Mac) |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 392 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
393 if (usb_keycode_map[i].native_keycode == native_keycode) { | 393 if (usb_keycode_map[i].native_keycode == native_keycode) { |
394 if (usb_keycode_map[i].code != NULL) | 394 if (usb_keycode_map[i].code != NULL) |
395 return usb_keycode_map[i].code; | 395 return usb_keycode_map[i].code; |
396 break; | 396 break; |
397 } | 397 } |
398 } | 398 } |
399 return InvalidKeyboardEventCode(); | 399 return InvalidKeyboardEventCode(); |
400 } | 400 } |
401 | 401 |
402 inline uint16_t CodeToNativeKeycode(const char* code) { | |
403 if (!code || | |
404 strcmp(code, InvalidKeyboardEventCode()) == 0) | |
Wez
2013/09/05 19:07:02
nit: It's best to treat an if as multi-line, and t
weitao
2013/09/05 22:02:09
Done.
| |
405 return InvalidNativeKeycode(); | |
406 | |
407 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | |
408 if (usb_keycode_map[i].code && strcmp(usb_keycode_map[i].code, code) == 0) | |
409 return usb_keycode_map[i].native_keycode; | |
410 } | |
411 return InvalidNativeKeycode(); | |
412 } | |
413 | |
402 // USB keycodes | 414 // USB keycodes |
403 // Note that USB keycodes are not part of any web standard. | 415 // Note that USB keycodes are not part of any web standard. |
404 // Please don't use USB keycodes in new code. | 416 // Please don't use USB keycodes in new code. |
405 | 417 |
406 inline uint16_t InvalidUsbKeycode() { | 418 inline uint16_t InvalidUsbKeycode() { |
407 return usb_keycode_map[0].usb_keycode; | 419 return usb_keycode_map[0].usb_keycode; |
408 } | 420 } |
409 | 421 |
410 inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { | 422 inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { |
411 // Deal with some special-cases that don't fit the 1:1 mapping. | 423 // Deal with some special-cases that don't fit the 1:1 mapping. |
(...skipping 19 matching lines...) Expand all Loading... | |
431 return InvalidUsbKeycode(); | 443 return InvalidUsbKeycode(); |
432 } | 444 } |
433 | 445 |
434 inline const char* UsbKeycodeToCode(uint32_t usb_keycode) { | 446 inline const char* UsbKeycodeToCode(uint32_t usb_keycode) { |
435 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 447 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
436 if (usb_keycode_map[i].usb_keycode == usb_keycode) | 448 if (usb_keycode_map[i].usb_keycode == usb_keycode) |
437 return usb_keycode_map[i].code; | 449 return usb_keycode_map[i].code; |
438 } | 450 } |
439 return InvalidKeyboardEventCode(); | 451 return InvalidKeyboardEventCode(); |
440 } | 452 } |
OLD | NEW |