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 <time.h> |
27 |
#include "rdesktop.h" |
#include "rdesktop.h" |
28 |
#include "scancodes.h" |
#include "scancodes.h" |
29 |
|
|
176 |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
177 |
} |
} |
178 |
|
|
179 |
|
if (strstr(line_rest, "inhibit")) |
180 |
|
{ |
181 |
|
MASK_ADD_BITS(modifiers, MapInhibitMask); |
182 |
|
} |
183 |
|
|
184 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
185 |
|
|
186 |
if (strstr(line_rest, "addupper")) |
if (strstr(line_rest, "addupper")) |
201 |
|
|
202 |
/* Before connecting and creating UI */ |
/* Before connecting and creating UI */ |
203 |
void |
void |
204 |
xkeymap_init1(void) |
xkeymap_init(void) |
205 |
{ |
{ |
206 |
int i; |
unsigned int max_keycode; |
|
|
|
|
/* Zeroing keymap */ |
|
|
for (i = 0; i < KEYMAP_SIZE; i++) |
|
|
{ |
|
|
keymap[i].scancode = 0; |
|
|
keymap[i].modifiers = 0; |
|
|
} |
|
207 |
|
|
208 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
|
{ |
|
209 |
xkeymap_read(keymapname); |
xkeymap_read(keymapname); |
|
} |
|
210 |
|
|
211 |
|
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
212 |
} |
} |
213 |
|
|
214 |
/* After connecting and creating UI */ |
/* Handles, for example, multi-scancode keypresses (which is not |
215 |
void |
possible via keymap-files) */ |
216 |
xkeymap_init2(void) |
BOOL |
217 |
|
handle_special_keys(uint32 keysym, uint32 ev_time, BOOL pressed) |
218 |
{ |
{ |
219 |
unsigned int max_keycode; |
switch (keysym) |
220 |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
{ |
221 |
|
case XK_Break: |
222 |
|
if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) |
223 |
|
{ |
224 |
|
/* toggle full screen */ |
225 |
|
if (pressed) |
226 |
|
xwin_toggle_fullscreen(); |
227 |
|
|
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; |
272 |
|
|
273 |
|
case XK_Meta_L: /* Windows keys */ |
274 |
|
case XK_Super_L: |
275 |
|
case XK_Hyper_L: |
276 |
|
case XK_Meta_R: |
277 |
|
case XK_Super_R: |
278 |
|
case XK_Hyper_R: |
279 |
|
if (pressed) |
280 |
|
{ |
281 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
282 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
283 |
|
} |
284 |
|
else |
285 |
|
{ |
286 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
287 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
288 |
|
} |
289 |
|
return True; |
290 |
|
break; |
291 |
|
} |
292 |
|
return False; |
293 |
} |
} |
294 |
|
|
295 |
|
|
296 |
key_translation |
key_translation |
297 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state) |
298 |
{ |
{ |
299 |
key_translation tr = { 0, 0 }; |
key_translation tr = { 0, 0 }; |
300 |
|
|
301 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
302 |
|
|
303 |
|
if (tr.modifiers & MapInhibitMask) |
304 |
|
{ |
305 |
|
DEBUG_KBD(("Inhibiting key\n")); |
306 |
|
tr.scancode = 0; |
307 |
|
return tr; |
308 |
|
} |
309 |
|
|
310 |
if (tr.modifiers & MapLocalStateMask) |
if (tr.modifiers & MapLocalStateMask) |
311 |
{ |
{ |
312 |
/* The modifiers to send for this key should be obtained |
/* The modifiers to send for this key should be obtained |
319 |
|
|
320 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
321 |
{ |
{ |
322 |
DEBUG_KBD |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
323 |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
tr.scancode, tr.modifiers)); |
|
tr.scancode, tr.modifiers)); |
|
324 |
return tr; |
return tr; |
325 |
} |
} |
326 |
|
|
327 |
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))); |
328 |
|
|
329 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
330 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
331 |
{ |
{ |
332 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
333 |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
|
334 |
|
/* The modifiers to send for this key should be |
335 |
|
obtained from the local state. Currently, only |
336 |
|
shift is implemented. */ |
337 |
|
if (state & ShiftMask) |
338 |
|
{ |
339 |
|
tr.modifiers = MapLeftShiftMask; |
340 |
|
} |
341 |
|
|
342 |
|
DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode)); |
343 |
} |
} |
344 |
else |
else |
345 |
{ |
{ |
346 |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode)); |
347 |
} |
} |
348 |
|
|
349 |
return tr; |
return tr; |
370 |
} |
} |
371 |
|
|
372 |
char * |
char * |
373 |
get_ksname(KeySym keysym) |
get_ksname(uint32 keysym) |
374 |
{ |
{ |
375 |
char *ksname = NULL; |
char *ksname = NULL; |
376 |
|
|
382 |
return ksname; |
return ksname; |
383 |
} |
} |
384 |
|
|
|
BOOL |
|
|
inhibit_key(KeySym keysym) |
|
|
{ |
|
|
switch (keysym) |
|
|
{ |
|
|
case XK_Caps_Lock: |
|
|
return True; |
|
|
break; |
|
|
case XK_Multi_key: |
|
|
return True; |
|
|
break; |
|
|
case XK_Num_Lock: |
|
|
return True; |
|
|
break; |
|
|
default: |
|
|
break; |
|
|
} |
|
|
return False; |
|
|
} |
|
385 |
|
|
386 |
void |
void |
387 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
403 |
break; |
break; |
404 |
} |
} |
405 |
|
|
406 |
/* Shift */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
407 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
408 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
409 |
{ |
{ |
410 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
411 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask)) |
412 |
{ |
{ |
413 |
/* Needs this modifier. Send down. */ |
/* Needs left shift. Send down. */ |
414 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
415 |
} |
} |
416 |
|
else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask)) |
417 |
|
{ |
418 |
|
/* Needs right shift. Send down. */ |
419 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT); |
420 |
|
} |
421 |
else |
else |
422 |
{ |
{ |
423 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up for shift currently pressed. */ |
424 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)) |
425 |
|
/* Left shift is down */ |
426 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
427 |
|
else |
428 |
|
/* Right shift is down */ |
429 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
430 |
} |
} |
431 |
} |
} |
432 |
|
|
470 |
} |
} |
471 |
|
|
472 |
|
|
473 |
|
void |
474 |
|
reset_modifier_keys(void) |
475 |
|
{ |
476 |
|
/* reset keys */ |
477 |
|
uint32 ev_time; |
478 |
|
ev_time = time(NULL); |
479 |
|
|
480 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
481 |
|
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)) |
484 |
|
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)) |
487 |
|
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)) |
490 |
|
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)) |
493 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
494 |
|
|
495 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
496 |
|
!get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) |
497 |
|
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(uint16 modifiers, BOOL pressed) |
503 |
{ |
{ |