<br>Hello. I'm writing an LCD controller, and one feature I'd like is the ability to interact with an LCD via the keyboard. I have the following code, but only the FocusOut/FocusIn events are firing.<br><div class="gmail_quote">
<br>static Window GetCurrWindow(Display *d) {<br>
Window foo;<br> Window win;<br> int bar;<br><br> do{<br> (void) XQueryPointer(d, DefaultRootWindow(d), &foo, &win,<br> &bar, &bar, &bar, &bar, (unsigned int *)&bar);<br>
} while(win <= 0);<br> return(win);<br>}<br><br>void PluginKeyboard::PluginPoll() {<br> Display *dpy = XOpenDisplay(NULL);<br> if(!dpy) {<br> LCDError("PluginKeyboard: Unable to open display.");<br>
return;<br> }<br><br> Window w = GetCurrWindow(dpy);<br> XSelectInput(dpy, w, FocusChangeMask|KeyPressMask|KeyReleaseMask);<br> while(started_) {<br><br> if(!XPending(dpy))<br> continue;<br>
<br> XEvent event;<br> char str[256+1];<br> KeySym ks;<br> char keycode;<br> int c;<br><br> XNextEvent(dpy, &event);<br><br> if(event.type == KeyPress) {<br> c = XLookupString((XKeyEvent *)&event, str, 256, &ks, NULL);<br>
<br> LCDError("KeyPressed");<br> if(c!=0)<br> continue;<br><br> keycode = XKeysymToKeycode(dpy, ks);<br><br> emit _KeyPressed(keycode);<br> LCDError("Keypressed: %d", keycode);<br>
}<br><br> if(event.type == KeyRelease) {<br> c = XLookupString((XKeyEvent *)&event, str, 256, &ks, NULL);<br><br> if(c!=0)<br> continue;<br><br> keycode = XKeysymToKeycode(dpy, ks);<br>
<br> emit _KeyReleased(keycode);<br> }<br><br> if(event.type == FocusOut) {<br> LCDError("FocusOut");<br> XSelectInput(dpy, w = GetCurrWindow(dpy),<br> FocusChangeMask|KeyPressMask|KeyReleaseMask);<br>
}<br><br> }<br>}<br><br>
</div><br>