40 |
static int min_keycode; |
static int min_keycode; |
41 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
42 |
|
|
43 |
static void update_modifier_state(uint16 modifiers, BOOL pressed); |
static void update_modifier_state(uint8 scancode, BOOL pressed); |
44 |
|
|
45 |
static void |
static void |
46 |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
214 |
/* Handles, for example, multi-scancode keypresses (which is not |
/* Handles, for example, multi-scancode keypresses (which is not |
215 |
possible via keymap-files) */ |
possible via keymap-files) */ |
216 |
BOOL |
BOOL |
217 |
handle_special_keys(uint32 keysym, uint32 ev_time, BOOL pressed) |
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed) |
218 |
{ |
{ |
219 |
switch (keysym) |
switch (keysym) |
220 |
{ |
{ |
221 |
case XK_Break: /* toggle full screen */ |
case XK_Break: |
222 |
if (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)) |
223 |
{ |
{ |
224 |
|
/* toggle full screen */ |
225 |
if (pressed) |
if (pressed) |
226 |
xwin_toggle_fullscreen(); |
xwin_toggle_fullscreen(); |
227 |
return True; |
|
228 |
|
} |
229 |
|
else |
230 |
|
{ |
231 |
|
/* Send Break sequence E0 46 E0 C6 */ |
232 |
|
if (pressed) |
233 |
|
{ |
234 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
235 |
|
(SCANCODE_EXTENDED | 0x46)); |
236 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
237 |
|
(SCANCODE_EXTENDED | 0xc6)); |
238 |
|
} |
239 |
|
/* No break sequence */ |
240 |
} |
} |
241 |
|
|
242 |
|
return True; |
243 |
|
break; |
244 |
|
|
245 |
|
case XK_Pause: |
246 |
|
/* According to MS Keyboard Scan Code |
247 |
|
Specification, pressing Pause should result |
248 |
|
in E1 1D 45 E1 9D C5. I'm not exactly sure |
249 |
|
of how this is supposed to be sent via |
250 |
|
RDP. The code below seems to work, but with |
251 |
|
the side effect that Left Ctrl stays |
252 |
|
down. Therefore, we release it when Pause |
253 |
|
is released. */ |
254 |
|
if (pressed) |
255 |
|
{ |
256 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
257 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); |
258 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); |
259 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
260 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); |
261 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); |
262 |
|
} |
263 |
|
else |
264 |
|
{ |
265 |
|
// Release Left Ctrl |
266 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, |
267 |
|
0); |
268 |
|
} |
269 |
|
|
270 |
|
return True; |
271 |
break; |
break; |
272 |
|
|
273 |
case XK_Meta_L: /* Windows keys */ |
case XK_Meta_L: /* Windows keys */ |
320 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
321 |
{ |
{ |
322 |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
323 |
tr.scancode, tr.modifiers)); |
tr.scancode, tr.modifiers)); |
324 |
return tr; |
return tr; |
325 |
} |
} |
326 |
|
|
471 |
|
|
472 |
|
|
473 |
void |
void |
474 |
reset_modifier_keys(void) |
reset_modifier_keys(unsigned int state) |
475 |
{ |
{ |
476 |
/* reset keys */ |
/* reset keys */ |
477 |
uint32 ev_time; |
uint32 ev_time; |
478 |
ev_time = time(NULL); |
ev_time = time(NULL); |
479 |
|
|
480 |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(state, XK_Shift_L)) |
481 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
482 |
|
|
483 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) |
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(state, XK_Shift_R)) |
484 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
485 |
|
|
486 |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(state, XK_Control_L)) |
487 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
488 |
|
|
489 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) |
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(state, XK_Control_R)) |
490 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
491 |
|
|
492 |
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)) |
493 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
494 |
|
|
495 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
496 |
!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)) |
497 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
498 |
} |
} |
499 |
|
|
500 |
|
|
501 |
static void |
static void |
502 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint8 scancode, BOOL pressed) |
503 |
{ |
{ |
504 |
#ifdef WITH_DEBUG_KBD |
#ifdef WITH_DEBUG_KBD |
505 |
uint16 old_modifier_state; |
uint16 old_modifier_state; |
507 |
old_modifier_state = remote_modifier_state; |
old_modifier_state = remote_modifier_state; |
508 |
#endif |
#endif |
509 |
|
|
510 |
switch (modifiers) |
switch (scancode) |
511 |
{ |
{ |
512 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
513 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
561 |
|
|
562 |
/* Send keyboard input */ |
/* Send keyboard input */ |
563 |
void |
void |
564 |
rdp_send_scancode(uint32 time, uint16 flags, uint16 scancode) |
rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode) |
565 |
{ |
{ |
566 |
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE)); |
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE)); |
567 |
|
|