<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.8.1">
</HEAD>
<BODY>
Hello,<BR>
<BR>
I wrote keyTouch (<A HREF="http://keytouch.sf.net">http://keytouch.sf.net</A>) which is a program for configuring extra function keys. It also includes a program keytouchd which is an X client that waits for a key press of an extra function key and then executes a program or a plugin.It is an X client without a window. And calls XGrabKey for every extra function key. Now I have written a plugin that simulates the F-keys (F1-F12) using the XTest extension. For some reason this doesn't work, because after calling the XTest functions the next XNextEvent call will give a key event of the simulated F-key. Yes I know what you are thinking: "he is grabbing those F-keys", but I am not. The plugin contains the following code:
<PRE>
void
emulate_key (KeySym keysym)
/*
Input:
keysym - The keysymbol of the key to emulate
Description:
This function sends a key press and release event of the key with symbol
keysym to the the default X display.
*/
{
Display *display;
int i;
KeyCode keycode;
/* Connect to the server specified in the DISPLAY evironment variable */
display = XOpenDisplay(NULL);
if (display == NULL)
{
fprintf (stderr, "Cannot connect to X server %s.\n", XDisplayName(NULL));
return;
}
if (!XQueryExtension (display, "XTEST", &i, &i, &i))
{
fprintf (stderr, "Extension XTest unavailable on display '%s'.\n", XDisplayName(NULL));
XCloseDisplay (display);
return;
}
keycode = XKeysymToKeycode(display, keysym);
/* Send the key press event */
XTestFakeKeyEvent(display, keycode, True, 0);
/* Send the key release event */
XTestFakeKeyEvent(display, keycode, False, 0);
XSync (display, False);
XCloseDisplay (display);
}
Note that the plugin opens a new connection to the X display for sending the key event, so that the connection of the main application is not used.
Is it a bug in Xlib or am I doing something wrong?
Regards,
Marvin Raaijmakers
</PRE>
</BODY>
</HTML>