Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: webkit/plugins/ppapi/usb_key_code_conversion_win.cc

Issue 9619014: Add Windows nativeKeyCode to USB keycode conversion table (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/usb_key_code_conversion.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
Wez 2012/03/07 23:35:50 We probably need a comment indicating that the tab
4
5 #include "webkit/plugins/ppapi/usb_key_code_conversion.h"
6
7 #include "base/logging.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
9
10 using WebKit::WebKeyboardEvent;
11
12 namespace webkit {
13 namespace ppapi {
14
15 namespace {
16
17 uint8_t win_scancode_to_usb[128] = {
Wez 2012/03/07 23:35:50 This table should be laid out in blocks of e.g. 4
Wez 2012/03/07 23:35:50 Your table has 128 entries, but the scancode is an
18 // 00: unused
19 0x00,
20 // 01: Escape
21 0x29,
22 // 02-0b: 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0)
Wez 2012/03/07 23:35:50 Please put commas between the key names, to make t
23 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
24 0x24, 0x25, 0x26, 0x27,
25 // 0c-0d: -_ =+
26 0x2d, 0x2e,
27 // 0e-0f: Backspace Tab
28 0x2a, 0x2b,
29 // 10-19: qQ wW eE rR tT yY uU iI oO pP
30 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c,
31 0x12, 0x13,
32 // 1a-1d: [{ ]} Enter LeftControl
33 0x2f, 0x30, 0x28, 0xe0,
34 // 1e-26: aA sS dD fF gG hH jJ kK lL
35 0x04, 0x16,
36 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f,
37 // 27-2a: ;: '" `~ LeftShift
38 0x33,
39 0x34, 0x35, 0xe1,
40 // 2b: \| (US keyboards only)
41 0x31,
42 // 2c-32: zZ xX cC vV bB nN mM
43 0x1d, 0x1b, 0x06, 0x19,
44 0x05, 0x11, 0x10,
45 // 33-36: ,< .> /? RightShift
46 0x36, 0x37, 0x38, 0xe5,
47 // 37: unused
48 0x00,
49 // 38-3a: LeftAlt Space CapsLock
50 0xe2, 0x2c, 0x39,
51 // 3b-44: F1 ... F10
52 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
53 0x3f, 0x40, 0x41, 0x42, 0x43,
54 // 45: NumLock
55 0x53,
56 // 46: ScrollLock
57 0x47,
58 // 47-4a: KP_7 KP_8 KP_9 KP_-
59 0x5f,
60 0x60, 0x61, 0x56,
61 // 4b-4e: KP_4 KP_5 KP_6 KP_+
62 0x5c, 0x5d, 0x5e, 0x57,
63 // 4f-53: KP_1 KP_2 KP_3 KP_0 KP_.
64 0x59,
65 0x5a, 0x5b, 0x62, 0x63,
66 // 54-5a: unused
67 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00,
69 // 5b-5d: F13 F14 F15
70 0x68, 0x69, 0x6a,
71 // 5e-62: unused
72 0x00, 0x00,
73 0x00, 0x00, 0x00,
74 // 63-6b: F16 ... F24
75 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
76 0x70, 0x71, 0x72, 0x73,
77 // 6c-7f: unused
78 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
81 };
82
83 uint8_t win_extended_scancode_to_usb[128] = {
84 // 00-1b: unused
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00,
89 // 1c-1d: Keypad_Enter RightControl
90 0x58, 0xe4,
91 // 1e-34: unused
92 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00,
96 // 35: Keypad_/
97 0x54,
98 // 36: unused
99 0x00,
100 // 37: PrintScreen
101 0x46,
102 // 38: RightAlt
103 0xe6,
104 // 39-44: unused
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00,
107 // 45-46: unused
108 0x00, 0x00,
109 // 47: Home
110 0x4a,
111 // 48-49: UpArrow PageUp
112 0x52, 0x4b,
113 // 4a: unused
114 0x00,
115 // 4b: LeftArrow
116 0x50,
117 // 4c: unused
118 0x00,
119 // 4d: RightArrow
120 0x4f,
121 // 4e: unused
122 0x00,
123 // 4f: End
124 0x4d,
125 // 50-53: DownArrow PageDown Insert Delete
126 0x51, 0x4e, 0x49, 0x4c,
127 // 54-5a: unused
128 0x00, 0x00, 0x00, 0x00,
129 0x00, 0x00, 0x00,
130 // 5b-5d: LeftWin RightWin AppsMenu
131 0xe3, 0xe7, 0x65,
132 // 5e-5f: Power Sleep
133 0x00, 0x00,
134 // 60-7f: unused
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
139 };
140
141 } // anonymous namespace
142
143 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) {
144 // The |nativeKeycode| on Windows comes from the key event's lParam:
145 // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
146 // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
147 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 // |t p c 0 0 0 0 e <--scan-code--> <--------repeat-count--------->|
149 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
150 // transition state [t]: 0 for keydown, 1 for keyup
151 // previous key state [p]
152 // context code [c]
153 // extended key [e]: 1 for extended keys (like RightAlt, RightCtrl).
154 // scan-code: The scan code from the keyboard.
155 // repeat-count: The number of times the key is auto-repeated.
Wez 2012/03/07 23:35:50 This is more detail than we need here; we only car
156 int scancode = (key_event.nativeKeyCode >> 16) & 0x00FF;
157 if (scancode >= 128)
158 return 0;
159
160 bool extended = (key_event.nativeKeyCode & 0x1000000) != 0;
161 uint16_t usb_id = 0;
162 if (extended) {
Wez 2012/03/07 23:35:50 Merge the two tables into a single 512-entry table
163 usb_id = win_extended_scancode_to_usb[scancode];
164 } else {
165 usb_id = win_scancode_to_usb[scancode];
166 }
167 VLOG(3) << "Converting scancode: " << std::hex << scancode
168 << " extended: " << extended << " to usb: " << usb_id << std::dec;
169 if (usb_id == 0)
170 return 0;
171
172 uint32_t usbkeycode = 0x070000 | usb_id;
Wez 2012/03/07 23:35:50 Why are you hard-coding all keys to the keyboard p
173 return usbkeycode;
174 }
175
176 } // namespace ppapi
177 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/usb_key_code_conversion.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698