|
| |||
|
|
Re: keyboard in X #define BOOL int #define TRUE 1 #define FALSE 0 #include [Error: Irreparable invalid markup ('<stdio.h>') in entry. Owner must fix manually. Raw contents below.] #define BOOL int #define TRUE 1 #define FALSE 0 #include <stdio.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #define INITIAL_WIDTH 640 #define INITIAL_HEIGHT 600 #define INITIAL_X 100 #define INITIAL_Y 100 #define BORDER 2 /* outside the window */ int vz, hz; XWMHints xwmh= {(InputHint|StateHint),True,NormalState,0,0,0,0,0,0,}; process(ev) XEvent *ev; { KeySym ksr; XComposeStatus sio; int numch; char buf[10]; /* buffer is 10, but probably no keys use > 1 */ int n; numch= XLookupString(&(ev->xkey), buf, 5, &ksr, &sio); n = (int) buf[0]; printf("numch=%d, ksr= %d, bufchr=%d\n", numch, (int) ksr, n); } main (argc, argv) int argc; char *argv []; { Display *dpy; Window win; GC gc; unsigned long fg, bg, bd; unsigned long bw; XSizeHints xsh; XSetWindowAttributes xswa; XGCValues gcv; XEvent event; if ((dpy=XOpenDisplay(NULL))==NULL) {printf("Can not open X display"); exit(1); } fg= bd= BlackPixel (dpy, DefaultScreen(dpy)); bg= WhitePixel (dpy, DefaultScreen(dpy)); bw= BORDER; xsh.flags= (PPosition|PSize|PMinSize); xsh.height= INITIAL_HEIGHT; xsh.width= INITIAL_WIDTH; xsh.x= INITIAL_X; xsh.y= INITIAL_Y; xsh.min_width= 200; xsh.min_height= 200; win= XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), xsh.x, xsh.y, xsh.width, xsh.height, bw, bd, bg); XSetStandardProperties (dpy,win,argv[0],argv[0],None,argv,argc,&xsh); XSetWMHints (dpy, win, &xwmh); xswa.colormap= DefaultColormap(dpy, DefaultScreen(dpy)); XChangeWindowAttributes(dpy, win, CWColormap, &xswa); gcv.foreground= fg; gcv.background= bg; gc= XCreateGC (dpy, win, (GCForeground|GCBackground), &gcv); XSelectInput (dpy, win, ExposureMask|KeyPressMask); XMapWindow (dpy, win); /* main cycle */ while (1==1){ XNextEvent (dpy, &event); switch (event.type){ case KeyPress:{ process (&event); break; } } } } Добавить комментарий: |
|||