1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
User interface services - X keyboard mapping |
User interface services - X keyboard mapping |
4 |
Copyright (C) Matthew Chapman 1999-2001 |
|
5 |
|
Copyright (C) Matthew Chapman 1999-2002 |
6 |
|
Copyright (C) Peter Astrand <peter@cendio.se> 2003 |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
9 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
GNU General Public License for more details. |
GNU General Public License for more details. |
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
19 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
20 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
*/ |
*/ |
22 |
|
|
23 |
|
#ifdef RDP2VNC |
24 |
|
#include "vnc/x11stubs.h" |
25 |
|
#else |
26 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
27 |
#define XK_MISCELLANY |
#include <X11/keysym.h> |
28 |
#include <X11/keysymdef.h> |
#endif |
29 |
|
|
30 |
#include <ctype.h> |
#include <ctype.h> |
31 |
#include <limits.h> |
#include <limits.h> |
32 |
#include <time.h> |
#include <time.h> |
33 |
#include "rdesktop.h" |
#include "rdesktop.h" |
34 |
#include "scancodes.h" |
#include "scancodes.h" |
35 |
|
|
36 |
#define KEYMAP_SIZE 4096 |
#define KEYMAP_SIZE 0xffff+1 |
37 |
#define KEYMAP_MASK (KEYMAP_SIZE - 1) |
#define KEYMAP_MASK 0xffff |
38 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
39 |
|
|
40 |
extern Display *display; |
extern Display *g_display; |
41 |
|
extern Window g_wnd; |
42 |
extern char keymapname[16]; |
extern char keymapname[16]; |
43 |
extern int keylayout; |
extern int keylayout; |
44 |
extern BOOL enable_compose; |
extern int g_win_button_size; |
45 |
|
extern BOOL g_enable_compose; |
46 |
|
extern BOOL g_use_rdp5; |
47 |
|
|
48 |
|
static BOOL keymap_loaded; |
49 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
50 |
static int min_keycode; |
static int min_keycode; |
51 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
52 |
|
static uint16 saved_remote_modifier_state = 0; |
53 |
|
|
54 |
static void update_modifier_state(uint16 modifiers, BOOL pressed); |
static void update_modifier_state(uint8 scancode, BOOL pressed); |
55 |
|
|
56 |
static void |
static void |
57 |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
61 |
keysym = XStringToKeysym(keyname); |
keysym = XStringToKeysym(keyname); |
62 |
if (keysym == NoSymbol) |
if (keysym == NoSymbol) |
63 |
{ |
{ |
64 |
error("Bad keysym %s in keymap %s\n", keyname, mapname); |
DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); |
65 |
return; |
return; |
66 |
} |
} |
67 |
|
|
79 |
xkeymap_read(char *mapname) |
xkeymap_read(char *mapname) |
80 |
{ |
{ |
81 |
FILE *fp; |
FILE *fp; |
82 |
char line[KEYMAP_MAX_LINE_LENGTH], path[PATH_MAX]; |
char line[KEYMAP_MAX_LINE_LENGTH]; |
83 |
|
char path[PATH_MAX], inplace_path[PATH_MAX]; |
84 |
unsigned int line_num = 0; |
unsigned int line_num = 0; |
85 |
unsigned int line_length = 0; |
unsigned int line_length = 0; |
86 |
char *keyname, *p; |
char *keyname, *p; |
95 |
fp = fopen(path, "r"); |
fp = fopen(path, "r"); |
96 |
if (fp == NULL) |
if (fp == NULL) |
97 |
{ |
{ |
98 |
error("Failed to open keymap %s\n", path); |
/* in case we are running from the source tree */ |
99 |
return False; |
strcpy(inplace_path, "keymaps/"); |
100 |
|
strncat(inplace_path, mapname, sizeof(inplace_path) - sizeof("keymaps/")); |
101 |
|
|
102 |
|
fp = fopen(inplace_path, "r"); |
103 |
|
if (fp == NULL) |
104 |
|
{ |
105 |
|
error("Failed to open keymap %s\n", path); |
106 |
|
return False; |
107 |
|
} |
108 |
} |
} |
109 |
|
|
110 |
/* FIXME: More tolerant on white space */ |
/* FIXME: More tolerant on white space */ |
145 |
if (strncmp(line, "enable_compose", 15) == 0) |
if (strncmp(line, "enable_compose", 15) == 0) |
146 |
{ |
{ |
147 |
DEBUG_KBD(("Enabling compose handling\n")); |
DEBUG_KBD(("Enabling compose handling\n")); |
148 |
enable_compose = True; |
g_enable_compose = True; |
149 |
continue; |
continue; |
150 |
} |
} |
151 |
|
|
186 |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
187 |
} |
} |
188 |
|
|
|
if (strstr(line_rest, "numlock")) |
|
|
{ |
|
|
MASK_ADD_BITS(modifiers, MapNumLockMask); |
|
|
} |
|
|
|
|
189 |
if (strstr(line_rest, "localstate")) |
if (strstr(line_rest, "localstate")) |
190 |
{ |
{ |
191 |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
203 |
/* Automatically add uppercase key, with same modifiers |
/* Automatically add uppercase key, with same modifiers |
204 |
plus shift */ |
plus shift */ |
205 |
for (p = keyname; *p; p++) |
for (p = keyname; *p; p++) |
206 |
*p = toupper(*p); |
*p = toupper((int) *p); |
207 |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
208 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
209 |
} |
} |
219 |
xkeymap_init(void) |
xkeymap_init(void) |
220 |
{ |
{ |
221 |
unsigned int max_keycode; |
unsigned int max_keycode; |
222 |
|
char *mapname_ptr; |
223 |
|
|
224 |
|
/* Make keymapname lowercase */ |
225 |
|
mapname_ptr = keymapname; |
226 |
|
while (*mapname_ptr) |
227 |
|
{ |
228 |
|
*mapname_ptr = tolower((int) *mapname_ptr); |
229 |
|
mapname_ptr++; |
230 |
|
} |
231 |
|
|
232 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
233 |
xkeymap_read(keymapname); |
{ |
234 |
|
if (xkeymap_read(keymapname)) |
235 |
|
keymap_loaded = True; |
236 |
|
} |
237 |
|
|
238 |
|
XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode); |
239 |
|
} |
240 |
|
|
241 |
|
static void |
242 |
|
send_winkey(uint32 ev_time, BOOL pressed, BOOL leftkey) |
243 |
|
{ |
244 |
|
uint8 winkey; |
245 |
|
|
246 |
|
if (leftkey) |
247 |
|
winkey = SCANCODE_CHAR_LWIN; |
248 |
|
else |
249 |
|
winkey = SCANCODE_CHAR_RWIN; |
250 |
|
|
251 |
|
if (pressed) |
252 |
|
{ |
253 |
|
if (g_use_rdp5) |
254 |
|
{ |
255 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, winkey); |
256 |
|
} |
257 |
|
else |
258 |
|
{ |
259 |
|
/* RDP4 doesn't support winkey. Fake with Ctrl-Esc */ |
260 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
261 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
262 |
|
} |
263 |
|
} |
264 |
|
else |
265 |
|
{ |
266 |
|
/* key released */ |
267 |
|
if (g_use_rdp5) |
268 |
|
{ |
269 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, winkey); |
270 |
|
} |
271 |
|
else |
272 |
|
{ |
273 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
274 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
275 |
|
} |
276 |
|
} |
277 |
|
} |
278 |
|
|
279 |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
static void |
280 |
|
reset_winkey(uint32 ev_time) |
281 |
|
{ |
282 |
|
if (g_use_rdp5) |
283 |
|
{ |
284 |
|
/* For some reason, it seems to suffice to release |
285 |
|
*either* the left or right winkey. */ |
286 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LWIN); |
287 |
|
} |
288 |
} |
} |
289 |
|
|
290 |
/* Handles, for example, multi-scancode keypresses (which is not |
/* Handles, for example, multi-scancode keypresses (which is not |
291 |
possible via keymap-files) */ |
possible via keymap-files) */ |
292 |
BOOL |
BOOL |
293 |
handle_special_keys(uint32 keysym, uint32 ev_time, BOOL pressed) |
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed) |
294 |
{ |
{ |
295 |
switch (keysym) |
switch (keysym) |
296 |
{ |
{ |
297 |
case XK_Break: /* toggle full screen */ |
case XK_Return: |
298 |
if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) |
if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)) |
299 |
|
&& (get_key_state(state, XK_Control_L) |
300 |
|
|| get_key_state(state, XK_Control_R))) |
301 |
{ |
{ |
302 |
xwin_toggle_fullscreen(); |
/* Ctrl-Alt-Enter: toggle full screen */ |
303 |
|
if (pressed) |
304 |
|
xwin_toggle_fullscreen(); |
305 |
return True; |
return True; |
306 |
} |
} |
307 |
break; |
break; |
308 |
|
|
309 |
case XK_Meta_L: /* Windows keys */ |
case XK_Break: |
310 |
case XK_Super_L: |
/* Send Break sequence E0 46 E0 C6 */ |
311 |
case XK_Hyper_L: |
if (pressed) |
312 |
case XK_Meta_R: |
{ |
313 |
case XK_Super_R: |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
314 |
case XK_Hyper_R: |
(SCANCODE_EXTENDED | 0x46)); |
315 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
316 |
|
(SCANCODE_EXTENDED | 0xc6)); |
317 |
|
} |
318 |
|
/* No release sequence */ |
319 |
|
return True; |
320 |
|
|
321 |
|
case XK_Pause: |
322 |
|
/* According to MS Keyboard Scan Code |
323 |
|
Specification, pressing Pause should result |
324 |
|
in E1 1D 45 E1 9D C5. I'm not exactly sure |
325 |
|
of how this is supposed to be sent via |
326 |
|
RDP. The code below seems to work, but with |
327 |
|
the side effect that Left Ctrl stays |
328 |
|
down. Therefore, we release it when Pause |
329 |
|
is released. */ |
330 |
if (pressed) |
if (pressed) |
331 |
{ |
{ |
332 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
333 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); |
334 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); |
335 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
336 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); |
337 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); |
338 |
} |
} |
339 |
else |
else |
340 |
{ |
{ |
341 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
/* Release Left Ctrl */ |
342 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, |
343 |
|
0x1d, 0); |
344 |
} |
} |
345 |
return True; |
return True; |
346 |
break; |
|
347 |
|
case XK_Meta_L: /* Windows keys */ |
348 |
|
case XK_Super_L: |
349 |
|
case XK_Hyper_L: |
350 |
|
send_winkey(ev_time, pressed, True); |
351 |
|
return True; |
352 |
|
|
353 |
|
case XK_Meta_R: |
354 |
|
case XK_Super_R: |
355 |
|
case XK_Hyper_R: |
356 |
|
send_winkey(ev_time, pressed, False); |
357 |
|
return True; |
358 |
|
|
359 |
|
case XK_space: |
360 |
|
/* Prevent access to the Windows system menu in single app mode */ |
361 |
|
if (g_win_button_size |
362 |
|
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) |
363 |
|
return True; |
364 |
|
|
365 |
} |
} |
366 |
return False; |
return False; |
367 |
} |
} |
394 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
395 |
{ |
{ |
396 |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
397 |
tr.scancode, tr.modifiers)); |
tr.scancode, tr.modifiers)); |
398 |
return tr; |
return tr; |
399 |
} |
} |
400 |
|
|
401 |
DEBUG_KBD(("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); |
if (keymap_loaded) |
402 |
|
warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
403 |
|
|
404 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
405 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if (((int) keycode >= min_keycode) && (keycode <= 0x60)) |
406 |
{ |
{ |
407 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
408 |
|
|
457 |
return ksname; |
return ksname; |
458 |
} |
} |
459 |
|
|
460 |
|
static BOOL |
461 |
void |
is_modifier(uint8 scancode) |
|
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
|
462 |
{ |
{ |
463 |
/* If this key is a modifier, do nothing */ |
switch (scancode) |
|
switch (tr.scancode) |
|
464 |
{ |
{ |
465 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
466 |
case SCANCODE_CHAR_RSHIFT: |
case SCANCODE_CHAR_RSHIFT: |
471 |
case SCANCODE_CHAR_LWIN: |
case SCANCODE_CHAR_LWIN: |
472 |
case SCANCODE_CHAR_RWIN: |
case SCANCODE_CHAR_RWIN: |
473 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
474 |
return; |
return True; |
475 |
default: |
default: |
476 |
break; |
break; |
477 |
} |
} |
478 |
|
return False; |
479 |
|
} |
480 |
|
|
481 |
|
void |
482 |
|
save_remote_modifiers(uint8 scancode) |
483 |
|
{ |
484 |
|
if (is_modifier(scancode)) |
485 |
|
return; |
486 |
|
|
487 |
|
saved_remote_modifier_state = remote_modifier_state; |
488 |
|
} |
489 |
|
|
490 |
|
void |
491 |
|
restore_remote_modifiers(uint32 ev_time, uint8 scancode) |
492 |
|
{ |
493 |
|
key_translation dummy; |
494 |
|
|
495 |
|
if (is_modifier(scancode)) |
496 |
|
return; |
497 |
|
|
498 |
|
dummy.scancode = 0; |
499 |
|
dummy.modifiers = saved_remote_modifier_state; |
500 |
|
ensure_remote_modifiers(ev_time, dummy); |
501 |
|
} |
502 |
|
|
503 |
|
void |
504 |
|
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
505 |
|
{ |
506 |
|
/* If this key is a modifier, do nothing */ |
507 |
|
if (is_modifier(tr.scancode)) |
508 |
|
return; |
509 |
|
|
510 |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
511 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
551 |
} |
} |
552 |
} |
} |
553 |
|
|
|
/* NumLock */ |
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
|
{ |
|
|
/* The remote modifier state is not correct */ |
|
|
uint16 new_remote_state = 0; |
|
554 |
|
|
555 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
} |
|
{ |
|
|
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
|
|
new_remote_state |= KBD_FLAG_NUMLOCK; |
|
|
} |
|
|
else |
|
|
{ |
|
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
|
|
} |
|
556 |
|
|
557 |
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
|
558 |
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
unsigned int |
559 |
} |
read_keyboard_state() |
560 |
|
{ |
561 |
|
unsigned int state; |
562 |
|
Window wdummy; |
563 |
|
int dummy; |
564 |
|
|
565 |
|
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
566 |
|
return state; |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
uint16 |
571 |
|
ui_get_numlock_state(unsigned int state) |
572 |
|
{ |
573 |
|
uint16 numlock_state = 0; |
574 |
|
|
575 |
|
if (get_key_state(state, XK_Num_Lock)) |
576 |
|
numlock_state = KBD_FLAG_NUMLOCK; |
577 |
|
|
578 |
|
return numlock_state; |
579 |
} |
} |
580 |
|
|
581 |
|
|
582 |
void |
void |
583 |
reset_modifier_keys(void) |
reset_modifier_keys() |
584 |
{ |
{ |
585 |
|
unsigned int state = read_keyboard_state(); |
586 |
|
|
587 |
/* reset keys */ |
/* reset keys */ |
588 |
uint32 ev_time; |
uint32 ev_time; |
589 |
ev_time = time(NULL); |
ev_time = time(NULL); |
590 |
|
|
591 |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) |
592 |
|
&& !get_key_state(state, XK_Shift_L)) |
593 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
594 |
|
|
595 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) |
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) |
596 |
|
&& !get_key_state(state, XK_Shift_R)) |
597 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
598 |
|
|
599 |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) |
600 |
|
&& !get_key_state(state, XK_Control_L)) |
601 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
602 |
|
|
603 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) |
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) |
604 |
|
&& !get_key_state(state, XK_Control_R)) |
605 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
606 |
|
|
607 |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(state, XK_Alt_L)) |
608 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
609 |
|
|
610 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
611 |
!get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) |
!get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch)) |
612 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
613 |
|
|
614 |
|
reset_winkey(ev_time); |
615 |
|
|
616 |
|
rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0); |
617 |
} |
} |
618 |
|
|
619 |
|
|
620 |
static void |
static void |
621 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint8 scancode, BOOL pressed) |
622 |
{ |
{ |
623 |
#ifdef WITH_DEBUG_KBD |
#ifdef WITH_DEBUG_KBD |
624 |
uint16 old_modifier_state; |
uint16 old_modifier_state; |
626 |
old_modifier_state = remote_modifier_state; |
old_modifier_state = remote_modifier_state; |
627 |
#endif |
#endif |
628 |
|
|
629 |
switch (modifiers) |
switch (scancode) |
630 |
{ |
{ |
631 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
632 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
652 |
case SCANCODE_CHAR_RWIN: |
case SCANCODE_CHAR_RWIN: |
653 |
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed); |
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed); |
654 |
break; |
break; |
|
case SCANCODE_CHAR_NUMLOCK: |
|
|
/* KeyReleases for NumLocks are sent immediately. Toggle the |
|
|
modifier state only on Keypress */ |
|
|
if (pressed) |
|
|
{ |
|
|
BOOL newNumLockState; |
|
|
newNumLockState = |
|
|
(MASK_HAS_BITS |
|
|
(remote_modifier_state, MapNumLockMask) == False); |
|
|
MASK_CHANGE_BIT(remote_modifier_state, |
|
|
MapNumLockMask, newNumLockState); |
|
|
} |
|
|
break; |
|
655 |
} |
} |
656 |
|
|
657 |
#ifdef WITH_DEBUG_KBD |
#ifdef WITH_DEBUG_KBD |
667 |
|
|
668 |
/* Send keyboard input */ |
/* Send keyboard input */ |
669 |
void |
void |
670 |
rdp_send_scancode(uint32 time, uint16 flags, uint16 scancode) |
rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode) |
671 |
{ |
{ |
672 |
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE)); |
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE)); |
673 |
|
|