home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.windows.x
- Path: sparky!uunet!gatech!bloom-beacon!INTERNET!dont-send-mail-to-path-lines
- From: deveau@oceanroutes.ns.ca ("Terry J. Deveau")
- Subject: Re: Keyboard input with X
- Message-ID: <9208172009.AA24116@expo.lcs.mit.edu>
- Sender: deveau@oceanroutes.ns.ca
- Organization: Oceanroutes Canada Inc.
- References: <1992Aug15.160543.28140@msuinfo.cl.msu.edu>
- Date: Mon, 17 Aug 1992 20:09:31 GMT
- Lines: 77
-
- >
- > Can someone tell me how to determine which keys have been pressed w/i and X
- > program?
- >
- > The book I'm using says to use the function XLookupString() in the
- > event->xkey.keycode structure, BUT it doesn;t say how to. I wrote this code to
- > determine if the last key pressed was a space, but all my attempts end with a seg
- > fault....
- >
- >
- > if (XLookupString (event->xkey.keycode) == ' ')
- > {
- > etc.
- > }
- >
- > I would be grateful for any insight into this problem someone can give me.
- >
- The following will give you an idea of how I do it; sorry about not sending
- a piece of actual working code, but I pulled this together from a more
- complex function.
-
- char cmd[80], *ptr, *ptrc, *chr;
- Window win;
- XSetWindowAttributes Wattrib;
- XGCValues GCval;
- GC GCa;
- XCharStruct extent;
- XEvent evnt;
- long compse[5];
- XSizeHints szHints;
- KeySym ks;
-
- XNextEvent (dsp, &evnt);
- switch (evnt.type) {
- case ButtonPress : XRaiseWindow (dsp, win); break;
- case KeyPress : nc = XLookupString (&(evnt.xkey),cmd,sizeof cmd,NULL,compse);
- if (!str) { nc = -1; break; }
- if (IsCursorKey(ks=XLookupKeysym(&(evnt.xkey),0))) {
- int in, jn, go = 1, k = -1, kn, i, j, nch=0, ich[10];
-
- switch (ks) {
- case XK_Up : if (sz==1) { k = 0; kn = 1; } break;
- case XK_Down : if (sz==1) { k = data->nopt-1; kn = -1; } break;
- case XK_Right : if (sz>1) { ... }
- break;
- case XK_Left : if (sz>1) { ... }
- break;
- } }
- else {
- switch (ks) {
- case XK_Delete :
- case XK_DeleteChar : if (sz>1) { ... }
- break;
- default :
- for (chr=cmd; chr-cmd<nc; chr++) {
- switch (*chr) {
- case '\b' : ...
- break;
- case '\r' : nc = -1; break;
- default : if (ptr-str==sz) XBell (dsp, 100);
- else {
- if (sz>1) { ... }
- else if (NULL==strchr(str,*chr)) XBell (dsp, 100);
- else {
- *str = *chr;
- nc = -1; } } } } } }
- break;
- case MappingNotify : XRefreshKeyboardMapping (&(evnt.xmapping)); break;
- case Expose : if (!evnt.xexpose.count) {
- paintWindow(dsp, win, &GCa, data);
- if (str && sz>1) {
- XSetForeground (dsp, GCa, colour_text);
- XDrawString (dsp, win, GCa, left, line, str, ptr-str);
- XSetForeground (dsp, GCa, colour_cursor);
- XDrawString (dsp, win, GCa, cursor-2, line, "_", 1); } }
- break; }
-
-