c++ - XNextEvent Doesn't works for some reason -


i'm trying catch keypress events using xlib. reasons xnextevent not working. i'm not receiving errors, looks program stuck on line of "xnextevent" call. here code:

#include <iostream> #include <cstdio> #include <cstdlib> #include <x11/xlib.h> #include <x11/xutil.h>  using namespace std;   int main() {     xevent event;     keysym key;     char text[255];     display *dis;      dis = xopendisplay(null);     while (1) {         xnextevent(dis, &event);         if (event.type==keypress && xlookupstring(&event.xkey,text,255,&key,0) == 1) {             if (text[0]=='q') {                 xclosedisplay(dis);                 return 0;             }             printf("you pressed %c key!\n", text[0]);         }     }     return 0; } 

this not how x11 windowing system works.

read this carefully. key point :

the source of event viewable window pointer in.

you not create window, therefore program doesn't receive keyboard events. if created window, has have focus :

the window used x server report these events depends on window's position in window hierarchy , whether intervening window prohibits generation of these events.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -