[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]
Re: Extended keyboard handling patch for rdesktop
To follow up my own post....
On Wed, 1 Nov 2000, Ben McKeegan wrote:
> As far as can tell my keyboard now works perfectly and is fully fuctional
> except for one issue: the num lock behavoir is erratic. It can take
> several presses to change the num lock status. This has the side effect
> that the num lock light gets out of sync with the actual numlock status.
> Has anybody else observed this problem?
As I latter discovered my caps lock key was affected by the same problem.
I found out what was causing this: windows appears to expect to recieve
both a key down and key release code every time the numlock or caplock key
is pressed. My X servers (various different ones from Xfree86 3.3.2.3a)
only send one code each time the key is pressed: 'key down' when the lock
is turned on and 'key release' when the lock is turned off.
I have attached a my revised patch against the 1.0.0 release version that
includes a workaround for this problem, but I would still be interested in
hearing if everybody else was suffering from it as it may be a problem
which is specific to my version of the xserver. If it is it will probably
be necessary to make this workaround a command line option.
/ Ben McKeegan, I.T. Manager \
\ Fitzwilliam College, University of Cambridge, UK. /
diff -u rdesktop-1.0.0.orig/constants.h rdesktop-1.0.0/constants.h
--- rdesktop-1.0.0.orig/constants.h Mon Oct 16 09:44:47 2000
+++ rdesktop-1.0.0/constants.h Thu Nov 2 10:47:03 2000
@@ -146,6 +146,7 @@
/* Device flags */
#define KBD_FLAG_RIGHT 0x0001
+#define KBD_FLAG_EXT 0x0100
#define KBD_FLAG_QUIET 0x1000
#define KBD_FLAG_DOWN 0x4000
#define KBD_FLAG_UP 0x8000
diff -u rdesktop-1.0.0.orig/xwin.c rdesktop-1.0.0/xwin.c
--- rdesktop-1.0.0.orig/xwin.c Mon Oct 16 09:44:48 2000
+++ rdesktop-1.0.0/xwin.c Thu Nov 2 10:51:17 2000
@@ -19,6 +19,7 @@
*/
#include <X11/Xlib.h>
+#include <X11/Xutil.h>
#include <time.h>
#include "rdesktop.h"
@@ -36,6 +37,7 @@
{
Screen *screen;
XSetWindowAttributes attribs;
+ XSizeHints *sizehints;
unsigned long input_mask;
int i;
@@ -67,6 +69,13 @@
0, 0, width, height, 0, 8, InputOutput, visual,
CWBackingStore | CWBackPixel, &attribs);
+ sizehints = XAllocSizeHints();
+ if (sizehints) {
+ sizehints->flags=PPosition;
+ XSetWMNormalHints(display,wnd,sizehints);
+ XFree(sizehints);
+ }
+
XStoreName(display, wnd, title);
XMapWindow(display, wnd);
@@ -99,18 +108,47 @@
switch (key)
{
- case 0x62: /* left arrow */
- return 0x48;
- case 0x64: /* up arrow */
- return 0x4b;
- case 0x66: /* down arrow */
- return 0x4d;
- case 0x68: /* right arrow */
- return 0x50;
- case 0x73: /* Windows key */
- DEBUG("CHECKPOINT\n");
+ case 0x61: /* home */
+ return 0x47 | 0x80;
+ case 0x62: /* up arrow */
+ return 0x48 | 0x80;
+ case 0x63: /* page up */
+ return 0x49 | 0x80;
+ case 0x64: /* left arrow */
+ return 0x4b | 0x80;
+
+ case 0x66: /* right arrow */
+ return 0x4d | 0x80;
+ case 0x67: /* end */
+ return 0x4f | 0x80;
+ case 0x68: /* down arrow */
+ return 0x50 | 0x80;
+ case 0x69: /* page down */
+ return 0x51 | 0x80;
+ case 0x6a: /* insert */
+ return 0x52 | 0x80;
+ case 0x6b: /* delete */
+ return 0x53 | 0x80;
+ case 0x6c: /* keypad enter */
+ return 0x1c | 0x80;
+ case 0x6d: /* right ctrl */
+ return 0x1d | 0x80;
+ case 0x6f: /* ctrl - print screen */
+ return 0x37 | 0x80;
+ case 0x70: /* keypad '/' */
+ return 0x35 | 0x80;
+ case 0x71: /* right alt */
+ return 0x38 | 0x80;
+ case 0x72: /* ctrl break */
+ return 0x46 | 0x80;
+ case 0x73: /* left window key */
+ return 0xff; /* real scancode is 5b */
+ case 0x74: /* right window key */
+ return 0xff; /* real scancode is 5c */
+ case 0x75: /* menu key */
+ return 0x5d | 0x80;
}
-
+
return 0;
}
@@ -150,8 +188,29 @@
if (scancode == 0)
break;
- rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,
+ if (scancode == 0xff) {
+ /* Window keys equivalent to ctrl-esc */
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ 0,0x1d, 0); /* ctrl down */
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ 0,1, 0); /* esc down */
+ break;
+ }
+
+ if (scancode & 0x80)
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ KBD_FLAG_EXT,
+ scancode & 0x7f, 0);
+ else
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,
+ scancode, 0);
+
+ /* Handle caps lock and num lock */
+ if (scancode==0x3a || scancode==0x45)
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ KBD_FLAG_DOWN | KBD_FLAG_UP,
scancode, 0);
+
break;
case KeyRelease:
@@ -159,9 +218,31 @@
if (scancode == 0)
break;
- rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
- KBD_FLAG_DOWN | KBD_FLAG_UP,
+ if (scancode == 0xff) {
+ /* Window keys equivalent to ctrl-esc */
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ KBD_FLAG_DOWN | KBD_FLAG_UP,
+ 0x1, 0); /* esc up */
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ KBD_FLAG_DOWN | KBD_FLAG_UP,
+ 0x1d, 0); /* ctrl up */
+ break;
+ }
+
+ /* Handle caps lock and num lock */
+ if (scancode==0x3a || scancode==0x45)
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,
scancode, 0);
+
+ if (scancode & 0x80)
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ KBD_FLAG_EXT |
+ KBD_FLAG_DOWN | KBD_FLAG_UP,
+ scancode & 0x7f, 0);
+ else
+ rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
+ KBD_FLAG_DOWN | KBD_FLAG_UP,
+ scancode, 0);
break;
case ButtonPress: