You are not logged in.
Pages: 1
Hi..
I'd like to type a small program which listens to keystroke events and executes a small script in response to it.
I'm not sure where to start, and I found it really hard to find anything useful on the net.
Say for instance that I want to capture the buttoncombination
Fn+F7 on my laptop, and execute some code in response to keypress.
I'm not interested in any existing program for this as I would just like to learn how to do it.
I realise that xev can give me some information on keypress. But that'll mean I have to write a loop which runs xev thousands of times a minute ? (sorry, haven't ready a whole lot about xev yet, just had my HD replaced the other day so I can't check it until the next day). Anyway, my point is that I would like to avoid polling.
This probably requires a java/c solution, and either is fine. (I doubt bash has mechanisms for this). Any pointers to documentation or similiar will be appreciated.
Thanks.
Offline
Seems like a fine program. Second best to typing one myself
Offline
I'm not interested in any existing program for this as I would just like to learn how to do it.
DOH! :oops: I need to learn how to read!
Offline
random crap:
Display *dpy = XOpenDisplay(NULL);
XEvent xev;
XGrabKey(dpy, AnyKey, AnyModifier, RootWindow(dpy), GrabModeAsync, True, GrabModeAsync);
XNextEvent(dpy,&xev);
switch(xev.type)
{
case KeyRelease:
case KeyPress:
KeySym sym = XKeycodeToKeysym(xev.xany.display, xev.xkey.keycode, 0);
if(sym != NoSymbol) printf("key=%s",XKeysymToString(sym));
break;
default:
break;
}
Now.. I wrote this from memory so I'm probably off alot. You'll also need an XGrabServer call in there to actually grab keyboard input for your app...
You can check just about every WM out there or keygrabbing code.
Offline
Thanks for the code. I Haven't gotten around to test it yet as my project list is running long I'll leave some feedback when I get the chance.
Offline
Pages: 1