00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef DEV_X_KBD_H
00024 #define DEV_X_KBD_H
00025
00026 #include "dev/kbd.H"
00027 #include "std/strings.H"
00028 #include <string.h>
00029 #include <X11/keysym.h>
00030 #include <X11/StringDefs.h>
00031 #include <X11/Intrinsic.h>
00032 #include <X11/Xatom.h>
00033
00034
00035
00036
00037
00038
00039
00040 class X_kbd : public DEVice_kbd {
00041 protected :
00042 static void key(Widget w,XtPointer client_data,XEvent *xevent,Boolean *) {
00043 XKeyEvent *kev((XKeyEvent *)xevent);
00044 X_kbd *kbd((X_kbd *)client_data);
00045 char buffer[1024], number;
00046 KeySym keysym;
00047
00048 if ((number = XLookupString(kev, buffer, 1024, &keysym, 0))) {
00049 if (keysym == XK_Return || keysym == XK_Linefeed)
00050 buffer[number-1] = '\n';
00051 buffer[number] = '\0';
00052 kbd->send_event(buffer[0], EVENTkbd::DOWN, kev->x, kev->y);
00053 } else if (keysym == XK_Shift_R || keysym == XK_Shift_L)
00054 kbd->send_event((char) EVENTkbd::SHIFT, EVENTkbd::DOWN, kev->x,kev->y);
00055 else if (keysym == XK_Control_R || keysym == XK_Control_L)
00056 kbd->send_event((char) EVENTkbd::CTRL, EVENTkbd::DOWN, kev->x, kev->y);
00057 }
00058 static void key_up(Widget w,XtPointer client_data,XEvent *xevent,Boolean *) {
00059 XKeyEvent *kev((XKeyEvent *)xevent);
00060 X_kbd *kbd((X_kbd *)client_data);
00061 char buffer[1024], number;
00062 KeySym keysym;
00063
00064 if ((number = XLookupString(kev, buffer, 1024, &keysym, 0))) {
00065 if (keysym == XK_Return || keysym == XK_Linefeed)
00066 buffer[number-1] = '\n';
00067 buffer[number] = '\0';
00068 kbd->send_event(buffer[0], EVENTkbd::UP, kev->x, kev->y);
00069 } else if (keysym == XK_Shift_R || keysym == XK_Shift_L)
00070 kbd->send_event((char) EVENTkbd::SHIFT, EVENTkbd::UP, kev->x, kev->y);
00071 else if (keysym == XK_Control_R || keysym == XK_Control_L)
00072 kbd->send_event((char) EVENTkbd::CTRL, EVENTkbd::UP, kev->x, kev->y);
00073 }
00074
00075 virtual void send_event(char key, EVENTkbd::trans t, int, int){ event(key,t);}
00076 Widget _widg;
00077
00078 public:
00079 X_kbd(Widget w, Cstr_ptr &n="kbd"):DEVice_kbd(n),_widg(w) {
00080 XtAddEventHandler(w, KeyPressMask, (Boolean)0, key, (void *)this);
00081 XtAddEventHandler(w, KeyReleaseMask, (Boolean)0, key_up,(void *)this);
00082 }
00083 };
00084 #endif