25 |
#include <string.h> |
#include <string.h> |
26 |
#include <ctype.h> |
#include <ctype.h> |
27 |
#include <limits.h> |
#include <limits.h> |
28 |
|
#include <assert.h> |
29 |
#include "rdesktop.h" |
#include "rdesktop.h" |
30 |
#include "scancodes.h" |
#include "scancodes.h" |
31 |
|
|
290 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
291 |
{ |
{ |
292 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
293 |
|
|
294 |
|
/* The modifiers to send for this key should be |
295 |
|
obtained from the local state. Currently, only |
296 |
|
shift is implemented. */ |
297 |
|
if (state & ShiftMask) |
298 |
|
{ |
299 |
|
tr.modifiers = MapLeftShiftMask; |
300 |
|
} |
301 |
|
|
302 |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
303 |
} |
} |
304 |
else |
else |
363 |
break; |
break; |
364 |
} |
} |
365 |
|
|
366 |
/* Shift */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
367 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
368 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
369 |
{ |
{ |
370 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
371 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask)) |
372 |
{ |
{ |
373 |
/* Needs this modifier. Send down. */ |
/* Needs left shift. Send down. */ |
374 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
375 |
} |
} |
376 |
|
else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask)) |
377 |
|
{ |
378 |
|
/* Needs right shift. Send down. */ |
379 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT); |
380 |
|
} |
381 |
else |
else |
382 |
{ |
{ |
383 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up for shift currently pressed. */ |
384 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)) |
385 |
|
/* Left shift is down */ |
386 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
387 |
|
else |
388 |
|
{ |
389 |
|
assert(MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask)); |
390 |
|
/* Right shift is down */ |
391 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
392 |
|
} |
393 |
|
|
394 |
} |
} |
395 |
} |
} |
396 |
|
|
434 |
} |
} |
435 |
|
|
436 |
|
|
437 |
|
void |
438 |
|
reset_modifier_keys() |
439 |
|
{ |
440 |
|
/* reset keys */ |
441 |
|
uint32 ev_time; |
442 |
|
ev_time = time(NULL); |
443 |
|
|
444 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
445 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
446 |
|
|
447 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) |
448 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
449 |
|
|
450 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) |
451 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
452 |
|
|
453 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) |
454 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
455 |
|
|
456 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) |
457 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
458 |
|
|
459 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
460 |
|
!get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) |
461 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
static void |
static void |
466 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
467 |
{ |
{ |