1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/host/event_executor_win.h"
#include <windows.h>
#include "app/keyboard_codes.h"
#include "base/stl_util-inl.h"
#include "remoting/host/capturer.h"
namespace remoting {
// TODO(hclam): Move this method to base.
// TODO(hclam): Using values look ugly, change it to something else.
static app::KeyboardCode WindowsKeyCodeForPosixKeyCode(int keycode) {
switch (keycode) {
case 0x08:
return app::VKEY_BACK;
case 0x09:
return app::VKEY_TAB;
case 0x0C:
return app::VKEY_CLEAR;
case 0x0D:
return app::VKEY_RETURN;
case 0x10:
return app::VKEY_SHIFT;
case 0x11:
return app::VKEY_CONTROL;
case 0x12:
return app::VKEY_MENU;
case 0x13:
return app::VKEY_PAUSE;
case 0x14:
return app::VKEY_CAPITAL;
case 0x15:
return app::VKEY_KANA;
case 0x17:
return app::VKEY_JUNJA;
case 0x18:
return app::VKEY_FINAL;
case 0x19:
return app::VKEY_KANJI;
case 0x1B:
return app::VKEY_ESCAPE;
case 0x1C:
return app::VKEY_CONVERT;
case 0x1D:
return app::VKEY_NONCONVERT;
case 0x1E:
return app::VKEY_ACCEPT;
case 0x1F:
return app::VKEY_MODECHANGE;
case 0x20:
return app::VKEY_SPACE;
case 0x21:
return app::VKEY_PRIOR;
case 0x22:
return app::VKEY_NEXT;
case 0x23:
return app::VKEY_END;
case 0x24:
return app::VKEY_HOME;
case 0x25:
return app::VKEY_LEFT;
case 0x26:
return app::VKEY_UP;
case 0x27:
return app::VKEY_RIGHT;
case 0x28:
return app::VKEY_DOWN;
case 0x29:
return app::VKEY_SELECT;
case 0x2A:
return app::VKEY_PRINT;
case 0x2B:
return app::VKEY_EXECUTE;
case 0x2C:
return app::VKEY_SNAPSHOT;
case 0x2D:
return app::VKEY_INSERT;
case 0x2E:
return app::VKEY_DELETE;
case 0x2F:
return app::VKEY_HELP;
case 0x30:
return app::VKEY_0;
case 0x31:
return app::VKEY_1;
case 0x32:
return app::VKEY_2;
case 0x33:
return app::VKEY_3;
case 0x34:
return app::VKEY_4;
case 0x35:
return app::VKEY_5;
case 0x36:
return app::VKEY_6;
case 0x37:
return app::VKEY_7;
case 0x38:
return app::VKEY_8;
case 0x39:
return app::VKEY_9;
case 0x41:
return app::VKEY_A;
case 0x42:
return app::VKEY_B;
case 0x43:
return app::VKEY_C;
case 0x44:
return app::VKEY_D;
case 0x45:
return app::VKEY_E;
case 0x46:
return app::VKEY_F;
case 0x47:
return app::VKEY_G;
case 0x48:
return app::VKEY_H;
case 0x49:
return app::VKEY_I;
case 0x4A:
return app::VKEY_J;
case 0x4B:
return app::VKEY_K;
case 0x4C:
return app::VKEY_L;
case 0x4D:
return app::VKEY_M;
case 0x4E:
return app::VKEY_N;
case 0x4F:
return app::VKEY_O;
case 0x50:
return app::VKEY_P;
case 0x51:
return app::VKEY_Q;
case 0x52:
return app::VKEY_R;
case 0x53:
return app::VKEY_S;
case 0x54:
return app::VKEY_T;
case 0x55:
return app::VKEY_U;
case 0x56:
return app::VKEY_V;
case 0x57:
return app::VKEY_W;
case 0x58:
return app::VKEY_X;
case 0x59:
return app::VKEY_Y;
case 0x5A:
return app::VKEY_Z;
case 0x5B:
return app::VKEY_LWIN;
case 0x5C:
return app::VKEY_RWIN;
case 0x5D:
return app::VKEY_APPS;
case 0x5F:
return app::VKEY_SLEEP;
case 0x60:
return app::VKEY_NUMPAD0;
case 0x61:
return app::VKEY_NUMPAD1;
case 0x62:
return app::VKEY_NUMPAD2;
case 0x63:
return app::VKEY_NUMPAD3;
case 0x64:
return app::VKEY_NUMPAD4;
case 0x65:
return app::VKEY_NUMPAD5;
case 0x66:
return app::VKEY_NUMPAD6;
case 0x67:
return app::VKEY_NUMPAD7;
case 0x68:
return app::VKEY_NUMPAD8;
case 0x69:
return app::VKEY_NUMPAD9;
case 0x6A:
return app::VKEY_MULTIPLY;
case 0x6B:
return app::VKEY_ADD;
case 0x6C:
return app::VKEY_SEPARATOR;
case 0x6D:
return app::VKEY_SUBTRACT;
case 0x6E:
return app::VKEY_DECIMAL;
case 0x6F:
return app::VKEY_DIVIDE;
case 0x70:
return app::VKEY_F1;
case 0x71:
return app::VKEY_F2;
case 0x72:
return app::VKEY_F3;
case 0x73:
return app::VKEY_F4;
case 0x74:
return app::VKEY_F5;
case 0x75:
return app::VKEY_F6;
case 0x76:
return app::VKEY_F7;
case 0x77:
return app::VKEY_F8;
case 0x78:
return app::VKEY_F9;
case 0x79:
return app::VKEY_F10;
case 0x7A:
return app::VKEY_F11;
case 0x7B:
return app::VKEY_F12;
case 0x7C:
return app::VKEY_F13;
case 0x7D:
return app::VKEY_F14;
case 0x7E:
return app::VKEY_F15;
case 0x7F:
return app::VKEY_F16;
case 0x80:
return app::VKEY_F17;
case 0x81:
return app::VKEY_F18;
case 0x82:
return app::VKEY_F19;
case 0x83:
return app::VKEY_F20;
case 0x84:
return app::VKEY_F21;
case 0x85:
return app::VKEY_F22;
case 0x86:
return app::VKEY_F23;
case 0x87:
return app::VKEY_F24;
case 0x90:
return app::VKEY_NUMLOCK;
case 0x91:
return app::VKEY_SCROLL;
case 0xA0:
return app::VKEY_LSHIFT;
case 0xA1:
return app::VKEY_RSHIFT;
case 0xA2:
return app::VKEY_LCONTROL;
case 0xA3:
return app::VKEY_RCONTROL;
case 0xA4:
return app::VKEY_LMENU;
case 0xA5:
return app::VKEY_RMENU;
case 0xA6:
return app::VKEY_BROWSER_BACK;
case 0xA7:
return app::VKEY_BROWSER_FORWARD;
case 0xA8:
return app::VKEY_BROWSER_REFRESH;
case 0xA9:
return app::VKEY_BROWSER_STOP;
case 0xAA:
return app::VKEY_BROWSER_SEARCH;
case 0xAB:
return app::VKEY_BROWSER_FAVORITES;
case 0xAC:
return app::VKEY_BROWSER_HOME;
case 0xAD:
return app::VKEY_VOLUME_MUTE;
case 0xAE:
return app::VKEY_VOLUME_DOWN;
case 0xAF:
return app::VKEY_VOLUME_UP;
case 0xB0:
return app::VKEY_MEDIA_NEXT_TRACK;
case 0xB1:
return app::VKEY_MEDIA_PREV_TRACK;
case 0xB2:
return app::VKEY_MEDIA_STOP;
case 0xB3:
return app::VKEY_MEDIA_PLAY_PAUSE;
case 0xB4:
return app::VKEY_MEDIA_LAUNCH_MAIL;
case 0xB5:
return app::VKEY_MEDIA_LAUNCH_MEDIA_SELECT;
case 0xB6:
return app::VKEY_MEDIA_LAUNCH_APP1;
case 0xB7:
return app::VKEY_MEDIA_LAUNCH_APP2;
case 0xBA:
return app::VKEY_OEM_1;
case 0xBB:
return app::VKEY_OEM_PLUS;
case 0xBC:
return app::VKEY_OEM_COMMA;
case 0xBD:
return app::VKEY_OEM_MINUS;
case 0xBE:
return app::VKEY_OEM_PERIOD;
case 0xBF:
return app::VKEY_OEM_2;
case 0xC0:
return app::VKEY_OEM_3;
case 0xDB:
return app::VKEY_OEM_4;
case 0xDC:
return app::VKEY_OEM_5;
case 0xDD:
return app::VKEY_OEM_6;
case 0xDE:
return app::VKEY_OEM_7;
case 0xDF:
return app::VKEY_OEM_8;
case 0xE2:
return app::VKEY_OEM_102;
case 0xE5:
return app::VKEY_PROCESSKEY;
case 0xE7:
return app::VKEY_PACKET;
case 0xF6:
return app::VKEY_ATTN;
case 0xF7:
return app::VKEY_CRSEL;
case 0xF8:
return app::VKEY_EXSEL;
case 0xF9:
return app::VKEY_EREOF;
case 0xFA:
return app::VKEY_PLAY;
case 0xFB:
return app::VKEY_ZOOM;
case 0xFC:
return app::VKEY_NONAME;
case 0xFD:
return app::VKEY_PA1;
case 0xFE:
return app::VKEY_OEM_CLEAR;
default:
return app::VKEY_UNKNOWN;
}
}
EventExecutorWin::EventExecutorWin(Capturer* capturer)
: EventExecutor(capturer) {
}
EventExecutorWin::~EventExecutorWin() {
}
void EventExecutorWin::HandleInputEvents(ClientMessageList* messages) {
for (size_t i = 0; i < messages->size(); ++i) {
ChromotingClientMessage* msg = (*messages)[i];
if (msg->has_mouse_set_position_event()) {
HandleMouseSetPosition(msg);
} else if (msg->has_mouse_move_event()) {
HandleMouseMove(msg);
} else if (msg->has_mouse_wheel_event()) {
HandleMouseWheel(msg);
} else if (msg->has_mouse_down_event()) {
HandleMouseButtonDown(msg);
} else if (msg->has_mouse_up_event()) {
HandleMouseButtonUp(msg);
} else if (msg->has_key_event()) {
HandleKey(msg);
}
}
// We simply delete all messages.
// TODO(hclam): Delete messages processed.
STLDeleteElements<ClientMessageList>(messages);
}
void EventExecutorWin::HandleMouseSetPosition(ChromotingClientMessage* msg) {
int x = msg->mouse_set_position_event().x();
int y = msg->mouse_set_position_event().y();
int width = msg->mouse_set_position_event().width();
int height = msg->mouse_set_position_event().height();
// Get width and height from the capturer if they are missing from the
// message.
if (width == 0 || height == 0) {
width = capturer_->width();
height = capturer_->height();
}
if (width == 0 || height == 0) {
return;
}
INPUT input;
input.type = INPUT_MOUSE;
input.mi.time = 0;
input.mi.dx = static_cast<int>((x * 65535) / width);
input.mi.dy = static_cast<int>((y * 65535) / height);
input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
SendInput(1, &input, sizeof(INPUT));
}
void EventExecutorWin::HandleMouseMove(ChromotingClientMessage* msg) {
INPUT input;
input.type = INPUT_MOUSE;
input.mi.time = 0;
input.mi.dx = msg->mouse_move_event().offset_x();
input.mi.dy = msg->mouse_move_event().offset_y();
input.mi.dwFlags = MOUSEEVENTF_MOVE;
SendInput(1, &input, sizeof(INPUT));
}
void EventExecutorWin::HandleMouseWheel(ChromotingClientMessage* msg) {
INPUT input;
input.type = INPUT_MOUSE;
input.mi.time = 0;
int dx = msg->mouse_wheel_event().offset_x();
int dy = msg->mouse_wheel_event().offset_y();
if (dx != 0) {
input.mi.mouseData = dx;
input.mi.dwFlags = MOUSEEVENTF_HWHEEL;
SendInput(1, &input, sizeof(INPUT));
}
if (dy != 0) {
input.mi.mouseData = dy;
input.mi.dwFlags = MOUSEEVENTF_WHEEL;
SendInput(1, &input, sizeof(INPUT));
}
}
void EventExecutorWin::HandleMouseButtonDown(ChromotingClientMessage* msg) {
INPUT input;
input.type = INPUT_MOUSE;
input.mi.time = 0;
input.mi.dx = 0;
input.mi.dy = 0;
MouseButton button = msg->mouse_down_event().button();
if (button == MouseButtonLeft) {
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
} else if (button == MouseButtonMiddle) {
input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN;
} else if (button == MouseButtonRight) {
input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
} else {
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
}
SendInput(1, &input, sizeof(INPUT));
}
void EventExecutorWin::HandleMouseButtonUp(ChromotingClientMessage* msg) {
INPUT input;
input.type = INPUT_MOUSE;
input.mi.time = 0;
input.mi.dx = 0;
input.mi.dy = 0;
MouseButton button = msg->mouse_down_event().button();
if (button == MouseButtonLeft) {
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
} else if (button == MouseButtonMiddle) {
input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP;
} else if (button == MouseButtonRight) {
input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
} else {
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
}
SendInput(1, &input, sizeof(INPUT));
}
void EventExecutorWin::HandleKey(ChromotingClientMessage* msg) {
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.time = 0;
input.ki.wVk = 0;
input.ki.wScan = msg->key_event().key();
input.ki.dwFlags = KEYEVENTF_UNICODE;
if (!msg->key_event().pressed()) {
input.ki.dwFlags |= KEYEVENTF_KEYUP;
}
SendInput(1, &input, sizeof(INPUT));
}
} // namespace remoting
|