You are not logged in.

#1 2008-11-12 03:11:52

xdd123www
Member
Registered: 2008-11-12
Posts: 2

Key Combination with XLib and XGrabKey function ???

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);

XGrabKey(dpy, XKeysymToKeycode(dpy,XK_F9 )  , ControlMask , 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?

Offline

#2 2008-11-12 03:12:38

xdd123www
Member
Registered: 2008-11-12
Posts: 2

Re: Key Combination with XLib and XGrabKey function ???

but it works 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.

Last edited by xdd123www (2008-11-12 03:14:29)

Offline

Board footer

Powered by FluxBB