Re: XGrabKey
- From: Tristan Sloughter <kungfooguru gmail com>
- To: Mario Levinsky <levinsky mario gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: XGrabKey
- Date: Wed, 17 Aug 2005 16:02:35 -0500
I did this in my program tilda like this:
key_grab (gchar *key) {
XModifierKeymap *modmap;
unsigned int numlockmask = 0;
unsigned int modmask = 0;
gint i, j;
/* Key grabbing stuff taken from yeahconsole who took it from evilwm */
modmap = XGetModifierMapping(dpy);
for (i = 0; i < 8; i++) {
for (j = 0; j < modmap->max_keypermod; j++) {
if (modmap->modifiermap[i * modmap->max_keypermod + j] ==
XKeysymToKeycode(dpy, XK_Num_Lock)) {
numlockmask = (1 << i);
}
}
}
XFreeModifiermap(modmap);
if (strstr(key, "Control"))
modmask = modmask | ControlMask;
if (strstr(key, "Alt"))
modmask = modmask | Mod1Mask;
if (strstr(key, "Win"))
modmask = modmask | Mod4Mask;
if (strstr(key, "None"))
modmask = 0;
if (strtok(key, "+"))
key = XStringToKeysym(strtok(NULL, "+"));
XGrabKey(dpy, XKeysymToKeycode(dpy, key), modmask, root, True,
GrabModeAsync, GrabModeAsync);
XGrabKey(dpy, XKeysymToKeycode(dpy, key), LockMask | modmask, root,
True, GrabModeAsync, GrabModeAsync);
if (numlockmask)
{
XGrabKey(dpy, XKeysymToKeycode(dpy, key), numlockmask | modmask,
root, True, GrabModeAsync, GrabModeAsync);
XGrabKey(dpy, XKeysymToKeycode(dpy, key), numlockmask | LockMask
| modmask, root, True, GrabModeAsync, GrabModeAsync);
}
}
some_function()
{
KeySym grabbed_key;
XEvent event;
if (!(dpy = XOpenDisplay(NULL)))
fprintf (stderr, "Can't open Display %s", XDisplayName(NULL));
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
key_grab ();
for (;;)
{
XNextEvent(dpy, &event);
switch (event.type)
{
case KeyPress:
grabbed_key = XKeycodeToKeysym(dpy, event.xkey.keycode, 0);
if (key == grabbed_key)
{
WHATEVER_YOU_WANT_IT_TO_DO ();
break;
}
default:
break;
}
}
Sorry for the lots of source and no comments, just wanted to pop this
out quickly in hopes it would help you.
Tristan
Mario Levinsky wrote:
Hi!
I would like to make possilbe in my gtk+ application using global hot keys,
I found xbindkeys application, and use part of its code.
Usage is simple:
first I call this
void grab_keys(Display *dpy, Keys_t *keys, int nb_keys);
and after that I catch XKeyEvent.
In xbindkeys it works,
in gtk application I use instead of dpy
gdk_x11_display_get_xdisplay(gdk_screen_get_display(gtk_window_get_screen(GTK_WINDOW(topLevelWindow))))
instead of XKeyEvent
"key_press_event" of topLevelWindow,
but I got strange result, I press key and my window has focus, I can catch
all keys with the exclusion of which I give grab_keys functions,
and when my window has no focus I can not catch anything.
Any help?
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]