PDA

View Full Version : Key Combination with XLib and XGrabKey function



xdd123www
November 11th, 2008, 01:58 PM
Hi ,

Can anyone help me with XLib and XGrabKey function?
I want to add key combination to my application .
but it didn't work.

code:
--------------------------
Window root ;
XEvent event;

Display *dpy = XOpenDisplay(0);

if(!dpy)
{
printf("Error for openning display.\nExit..\n");
return ;
}

root = DefaultRootWindow(dpy);

KeyCode key = XKeysymToKeycode(dpy,XK_F9 ) ;


unsigned int mod = 0 ;
mod = mod | ControlMask ;

XGrabKey(dpy, key , mod , root,True, GrabModeAsync, GrabModeAsync);

for( ; ; )
{

XNextEvent(dpy, &event);
if(event.type == KeyPress && event.xkey.keycode == key ) //
{
// do sth...
}
}

XAllowEvents(dpy,AsyncKeyboard,CurrentTime);
XUngrabKey(dpy, key, AnyModifier, root);
XSync(dpy,false);

-----------------------

How should I use it to get it work?

xdd123www
November 12th, 2008, 03:54 AM
but it work well like this :

XGrabKey( dpy, XKeysymToKeycode(dpy,XK_F9 ) , AnyModifier , root,true, GrabModeAsync, GrabModeAsync ) ;


when i used 'ControlMask' ,
it seems that ,
"XNextEvent(dpy, &event);" didn't copy any event from queue .



Any help, much appreciated.