19 |
*/ |
*/ |
20 |
|
|
21 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
22 |
#include <X11/keysym.h> |
#define XK_MISCELLANY |
23 |
#include <stdio.h> |
#include <X11/keysymdef.h> |
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
24 |
#include <ctype.h> |
#include <ctype.h> |
25 |
#include <limits.h> |
#include <limits.h> |
26 |
#include <assert.h> |
#include <time.h> |
27 |
#include "rdesktop.h" |
#include "rdesktop.h" |
28 |
#include "scancodes.h" |
#include "scancodes.h" |
29 |
|
|
204 |
xkeymap_init(void) |
xkeymap_init(void) |
205 |
{ |
{ |
206 |
unsigned int max_keycode; |
unsigned int max_keycode; |
|
int i; |
|
207 |
|
|
208 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
209 |
xkeymap_read(keymapname); |
xkeymap_read(keymapname); |
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(KeySym keysym, uint32 ev_time, BOOL pressed) |
handle_special_keys(uint32 keysym, uint32 ev_time, BOOL pressed) |
218 |
{ |
{ |
219 |
switch (keysym) |
switch (keysym) |
220 |
{ |
{ |
221 |
case XK_Break: /* toggle full screen */ |
case XK_Break: /* toggle full screen */ |
222 |
if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) |
if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) |
223 |
{ |
{ |
224 |
xwin_toggle_fullscreen(); |
if (pressed) |
225 |
|
xwin_toggle_fullscreen(); |
226 |
return True; |
return True; |
227 |
} |
} |
228 |
break; |
break; |
229 |
|
|
230 |
|
case XK_Pause: |
231 |
|
/* According to MS Keyboard Scan Code |
232 |
|
Specification, pressing Pause should result |
233 |
|
in E1 1D 45 E1 9D C5. I'm not exactly sure |
234 |
|
of how this is supposed to be sent via |
235 |
|
RDP. The code below seems to work, but with |
236 |
|
the side effect that Left Ctrl stays |
237 |
|
down. Therefore, we release it when Pause |
238 |
|
is released. */ |
239 |
|
if (pressed) |
240 |
|
{ |
241 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
242 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); |
243 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); |
244 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
245 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); |
246 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); |
247 |
|
} |
248 |
|
else |
249 |
|
{ |
250 |
|
// Release Left Ctrl |
251 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, |
252 |
|
0); |
253 |
|
} |
254 |
|
|
255 |
|
return True; |
256 |
|
break; |
257 |
|
|
258 |
case XK_Meta_L: /* Windows keys */ |
case XK_Meta_L: /* Windows keys */ |
259 |
case XK_Super_L: |
case XK_Super_L: |
260 |
case XK_Hyper_L: |
case XK_Hyper_L: |
279 |
|
|
280 |
|
|
281 |
key_translation |
key_translation |
282 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state) |
283 |
{ |
{ |
284 |
key_translation tr = { 0, 0 }; |
key_translation tr = { 0, 0 }; |
285 |
|
|
304 |
|
|
305 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
306 |
{ |
{ |
307 |
DEBUG_KBD |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
308 |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
tr.scancode, tr.modifiers)); |
|
tr.scancode, tr.modifiers)); |
|
309 |
return tr; |
return tr; |
310 |
} |
} |
311 |
|
|
312 |
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))); |
313 |
|
|
314 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
315 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
324 |
tr.modifiers = MapLeftShiftMask; |
tr.modifiers = MapLeftShiftMask; |
325 |
} |
} |
326 |
|
|
327 |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode)); |
328 |
} |
} |
329 |
else |
else |
330 |
{ |
{ |
331 |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode)); |
332 |
} |
} |
333 |
|
|
334 |
return tr; |
return tr; |
355 |
} |
} |
356 |
|
|
357 |
char * |
char * |
358 |
get_ksname(KeySym keysym) |
get_ksname(uint32 keysym) |
359 |
{ |
{ |
360 |
char *ksname = NULL; |
char *ksname = NULL; |
361 |
|
|
410 |
/* Left shift is down */ |
/* Left shift is down */ |
411 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
412 |
else |
else |
|
{ |
|
|
assert(MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask)); |
|
413 |
/* Right shift is down */ |
/* Right shift is down */ |
414 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
|
} |
|
|
|
|
415 |
} |
} |
416 |
} |
} |
417 |
|
|
456 |
|
|
457 |
|
|
458 |
void |
void |
459 |
reset_modifier_keys() |
reset_modifier_keys(void) |
460 |
{ |
{ |
461 |
/* reset keys */ |
/* reset keys */ |
462 |
uint32 ev_time; |
uint32 ev_time; |