--- sourceforge.net/trunk/rdesktop/xkeymap.c 2002/09/16 13:21:44 165 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2002/09/24 07:59:14 192 @@ -19,12 +19,11 @@ */ #include -#include -#include -#include -#include +#define XK_MISCELLANY +#include #include #include +#include #include "rdesktop.h" #include "scancodes.h" @@ -205,7 +204,6 @@ xkeymap_init(void) { unsigned int max_keycode; - int i; if (strcmp(keymapname, "none")) xkeymap_read(keymapname); @@ -216,7 +214,7 @@ /* Handles, for example, multi-scancode keypresses (which is not possible via keymap-files) */ BOOL -handle_special_keys(KeySym keysym, uint32 ev_time, BOOL pressed) +handle_special_keys(uint32 keysym, uint32 ev_time, BOOL pressed) { switch (keysym) { @@ -252,7 +250,7 @@ key_translation -xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) +xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state) { key_translation tr = { 0, 0 }; @@ -277,13 +275,12 @@ if (tr.scancode != 0) { - DEBUG_KBD - (("Found key translation, scancode=0x%x, modifiers=0x%x\n", + DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", tr.scancode, tr.modifiers)); return tr; } - fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); + DEBUG_KBD(("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); /* not in keymap, try to interpret the raw scancode */ if ((keycode >= min_keycode) && (keycode <= 0x60)) @@ -298,11 +295,11 @@ tr.modifiers = MapLeftShiftMask; } - fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); + DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode)); } else { - fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); + DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode)); } return tr; @@ -329,7 +326,7 @@ } char * -get_ksname(KeySym keysym) +get_ksname(uint32 keysym) { char *ksname = NULL; @@ -362,21 +359,30 @@ break; } - /* Shift */ + /* Shift. Left shift and right shift are treated as equal; either is fine. */ if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) != MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) { /* The remote modifier state is not correct */ - if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) + if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask)) { - /* Needs this modifier. Send down. */ + /* Needs left shift. Send down. */ rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); } + else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask)) + { + /* Needs right shift. Send down. */ + rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT); + } else { - /* Should not use this modifier. Send up. */ - rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); - rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); + /* Should not use this modifier. Send up for shift currently pressed. */ + if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)) + /* Left shift is down */ + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); + else + /* Right shift is down */ + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); } } @@ -420,6 +426,34 @@ } +void +reset_modifier_keys(void) +{ + /* reset keys */ + uint32 ev_time; + ev_time = time(NULL); + + if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); + + if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); + + if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); + + if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); + + if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); + + if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && + !get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); +} + + static void update_modifier_state(uint16 modifiers, BOOL pressed) {