1 diff -u rdesktop-1.5.0.orig/xkeymap.c rdesktop-1.5.0/xkeymap.c
2 --- rdesktop-1.5.0.orig/xkeymap.c 2006-08-07 19:45:44.000000000 +0800
3 +++ rdesktop-1.5.0/xkeymap.c 2006-10-10 09:49:29.000000000 +0800
5 static int min_keycode;
6 static uint16 remote_modifier_state = 0;
7 static uint16 saved_remote_modifier_state = 0;
8 +static uint32 vkmenu, vkcontrol, vklshift, vkrshift, vknumlock;
10 static void update_modifier_state(uint8 scancode, BOOL pressed);
13 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
15 reset_winkey(ev_time);
16 + vknumlock = get_key_state(state, XK_Num_Lock);
19 rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0);
20 @@ -1034,3 +1036,153 @@
21 rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
25 +typedef unsigned char byte;
26 +typedef unsigned int dword;
28 +static byte vkscancode[ 128] = {
29 + /* 00 - 07 */ 0, 0, 0, 0, 0, 0, 0, 0,
30 + /* 08 - 0f */ 0, SCANCODE_CHAR_ESC, SCANCODE_CHAR_1, SCANCODE_CHAR_2, SCANCODE_CHAR_3, SCANCODE_CHAR_4, SCANCODE_CHAR_5, SCANCODE_CHAR_6,
31 + /* 10 - 17 */ SCANCODE_CHAR_7, SCANCODE_CHAR_8, SCANCODE_CHAR_9, SCANCODE_CHAR_0, SCANCODE_CHAR_MINUS, SCANCODE_CHAR_EQUAL, SCANCODE_CHAR_BACKSPACE, SCANCODE_CHAR_TAB,
32 + /* 18 - 1f */ SCANCODE_CHAR_Q, SCANCODE_CHAR_W, SCANCODE_CHAR_E, SCANCODE_CHAR_R, SCANCODE_CHAR_T, SCANCODE_CHAR_Y, SCANCODE_CHAR_U, SCANCODE_CHAR_I,
33 + /* 20 - 27 */ SCANCODE_CHAR_O, SCANCODE_CHAR_P, SCANCODE_CHAR_BRACKETLEFT, SCANCODE_CHAR_BRACKETRIGHT, SCANCODE_CHAR_ENTER, SCANCODE_CHAR_LCTRL, SCANCODE_CHAR_A, SCANCODE_CHAR_S,
34 + /* 28 - 2f */ SCANCODE_CHAR_D, SCANCODE_CHAR_F, SCANCODE_CHAR_G, SCANCODE_CHAR_H, SCANCODE_CHAR_J, SCANCODE_CHAR_K, SCANCODE_CHAR_L, SCANCODE_CHAR_SEMICOLON,
35 + /* 30 - 37 */ SCANCODE_CHAR_APOSTROPHE, SCANCODE_CHAR_GRAVE, SCANCODE_CHAR_LSHIFT, SCANCODE_KEY_42, SCANCODE_CHAR_Z, SCANCODE_CHAR_X, SCANCODE_CHAR_C, SCANCODE_CHAR_V,
36 + /* 38 - 3f */ SCANCODE_CHAR_B, SCANCODE_CHAR_N, SCANCODE_CHAR_M, SCANCODE_CHAR_COMMA, SCANCODE_CHAR_DOT, SCANCODE_CHAR_SLASH, SCANCODE_CHAR_RSHIFT, SCANCODE_CHAR_NUMERICSTAR,
37 + /* 40 - 47 */ SCANCODE_CHAR_LALT, SCANCODE_CHAR_SPACE, SCANCODE_CHAR_CAPSLOCK, SCANCODE_CHAR_F1, SCANCODE_CHAR_F2, SCANCODE_CHAR_F3, SCANCODE_CHAR_F4, SCANCODE_CHAR_F5,
38 + /* 48 - 4f */ SCANCODE_CHAR_F6, SCANCODE_CHAR_F7, SCANCODE_CHAR_F8, SCANCODE_CHAR_F9, SCANCODE_CHAR_F10, SCANCODE_CHAR_NUMLOCK, SCANCODE_CHAR_SCROLLLOCK, SCANCODE_CHAR_NUMERIC7,
39 + /* 50 - 57 */ SCANCODE_CHAR_NUMERIC8, SCANCODE_CHAR_NUMERIC9, SCANCODE_CHAR_NUMERICMINUS, SCANCODE_CHAR_NUMERIC4, SCANCODE_CHAR_NUMERIC5, SCANCODE_CHAR_NUMERIC6, SCANCODE_CHAR_NUMERICPLUS, SCANCODE_CHAR_NUMERIC1,
40 + /* 58 - 5f */ SCANCODE_CHAR_NUMERIC2, SCANCODE_CHAR_NUMERIC3, SCANCODE_CHAR_NUMERIC0, SCANCODE_CHAR_NUMERICDOT, 0, 0, 0, SCANCODE_CHAR_F11,
41 + /* 60 - 67 */ SCANCODE_CHAR_F12, SCANCODE_CHAR_HOME, SCANCODE_CHAR_UPARROW, SCANCODE_CHAR_PAGEUP, SCANCODE_CHAR_LARROW, 0, SCANCODE_CHAR_RARROW, SCANCODE_CHAR_END,
42 + /* 68 - 6f */ SCANCODE_CHAR_DNARROW, SCANCODE_CHAR_PAGEDOWN, SCANCODE_CHAR_INSERT, SCANCODE_CHAR_DELETE, SCANCODE_CHAR_NUMERICENTER, SCANCODE_CHAR_RCTRL, SCANCODE_CHAR_PAUSE, SCANCODE_CHAR_PRINT,
43 + /* 70 - 77 */ SCANCODE_CHAR_NUMERICSLASH, SCANCODE_CHAR_RALT, 0, SCANCODE_CHAR_LWIN, SCANCODE_CHAR_RWIN, SCANCODE_CHAR_APPLICATION, 0, 0,
44 + /* 78 - 7f */ 0, 0, 0, 0, 0, 0, 0, 0
48 +static inline int vk_handle_special_keys( uint32 keysym, uint32 ev_time, RD_BOOL pressed) {
50 + RD_BOOL leftkey = 0;
53 + case SCANCODE_CHAR_NUMLOCK:
55 + vknumlock = !vknumlock;
58 + case SCANCODE_CHAR_ENTER:
59 + case SCANCODE_CHAR_NUMERICENTER:
60 + if( pressed && vkmenu && vkcontrol) {
61 + /* Ctrl-Alt-Enter: toggle full screen */
62 + xwin_toggle_fullscreen();
67 + case SCANCODE_CHAR_PAUSE:
70 + rdp_send_scancode( ev_time, RDP_KEYPRESS, (SCANCODE_EXTENDED | 0x46));
71 + rdp_send_scancode( ev_time, RDP_KEYPRESS, (SCANCODE_EXTENDED | 0xc6));
74 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0);
75 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0);
76 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0);
77 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0);
78 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0);
79 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0);
83 + /* Release Left Ctrl */
85 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0);
89 + case SCANCODE_CHAR_PRINT:
91 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, pressed ? RDP_KEYPRESS : RDP_KEYRELEASE, 0x54, 0);
92 + else if( vkcontrol && (vklshift || vklshift))
93 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, pressed ? RDP_KEYPRESS : RDP_KEYRELEASE, SCANCODE_EXTENDED|0x37, 0);
97 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT, 0);
98 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, SCANCODE_EXTENDED|0x37, 0);
101 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, SCANCODE_EXTENDED|0x37, 0);
102 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT, 0);
108 + case SCANCODE_CHAR_LWIN:
110 + case SCANCODE_CHAR_RWIN:
113 + rdp_send_scancode(ev_time, RDP_KEYPRESS, keysym);
116 + /* RDP4 doesn't support winkey. Fake with Ctrl-Esc */
117 + rdp_send_scancode( ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL);
118 + rdp_send_scancode( ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC);
123 + rdp_send_scancode(ev_time, RDP_KEYRELEASE, keysym);
126 + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC);
127 + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
132 + case SCANCODE_CHAR_INSERT:
133 + case SCANCODE_CHAR_DELETE:
134 + case SCANCODE_CHAR_LARROW:
135 + case SCANCODE_CHAR_HOME:
136 + case SCANCODE_CHAR_END:
137 + case SCANCODE_CHAR_UPARROW:
138 + case SCANCODE_CHAR_DNARROW:
139 + case SCANCODE_CHAR_PAGEUP:
140 + case SCANCODE_CHAR_PAGEDOWN:
141 + case SCANCODE_CHAR_RARROW:
142 + rdp_send_scancode( ev_time, pressed ? RDP_KEYPRESS : RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
143 + rdp_send_scancode( ev_time, pressed ? RDP_KEYPRESS : RDP_KEYRELEASE, keysym);
149 +void vk_handle_key( XKeyEvent *xkey) {
151 + uint32 vk, ev_time, pressed = (xkey->type == KeyPress);
153 + vk = vkscancode[ xkey->keycode];
154 + DEBUG_KBD(( "vk_handle_key( scancode=0x%x) vk = 0x%x\n", xkey->keycode, vk));
159 + ev_time = time( 0);
161 + if( (vk == SCANCODE_CHAR_LCTRL) || (vk == SCANCODE_CHAR_RCTRL))
162 + vkcontrol = pressed;
163 + else if( (vk == SCANCODE_CHAR_LALT) || (vk == SCANCODE_CHAR_RALT))
165 + else if( vk == SCANCODE_CHAR_LSHIFT)
166 + vklshift = pressed;
167 + else if( vk == SCANCODE_CHAR_RSHIFT)
168 + vkrshift = pressed;
169 + else if( vk_handle_special_keys( vk, ev_time, pressed))
172 + rdp_send_input( ev_time, RDP_INPUT_SCANCODE, pressed ? RDP_KEYPRESS : RDP_KEYRELEASE, vk, 0);