c++ - Linux X11 - Global Keyboard Hook -


is possible (or how) create mechanism (in linux x11, c++) works global hook in windows (setwindowshookex())?

i able catch key event possibility of further propagation. i'm trying use xgrabkey solution (like in xbindkeys) when set capturing key event, event "consumed".

requirements mechanism following:

  1. global / system-wide - catching events regardless of window has focus
  2. the possibility of "catch-hold" , "catch-pass through"
  3. it must quite fast

sample code looks this:

bool myflagisset = false; xevent event; while (true) {     while (xpending(display) > 0) {         usleep(sleep_time);     }      xnextevent(display, &event);     switch (e.type) {         case keypress:             if (myflagisset) {                 //do not propagate             }             // propagate             break;         case keyrelease:             if (myflagisset) {                 //do not propagate             }             // propagate             break;     } } 

on windows wrote:

if(event.isconsumed()) {     return lresult(1); } //... return callnexthookex(hookhandle, ncode, wparam, lparam); 

i've tried using xungrabkey , xsendevent:

switch (event.type) {     case keypress:         if (myflagisset) {             //do not propagate         }         // propagate         xungrabkey(...);         xsendevent(..., &event);         xgrabkey(...);         break;     case keyrelease:         ...     } 

unfortunately xsendevent unknown reasons me - not send event if xgrabkey line commented.

is possible complete approach?

please suggest other approach if condemned failure

edit

i implement on ubuntu gnome using compiz window manager

xsendevent() send it; it's regarded security hole, programs ignore ui events send_event flag set.

the standard x11 protocol doesn't allow this. xinput 2.0 extension might, doubt it; while windows assumes single event queue every program listens to, program can intercept event , prevent being sent down queue other listeners, every x11 client has own independent queue , clients register interest in event receive independent copy of in queue. means under normal circumstances it's impossible errant program block other programs running; means that, times when client must block other clients, must server grab prevent server processing events other client.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -