X client receives keys that are not grabbed

Marvin Raaijmakers marvin.nospam at gmail.com
Fri Apr 21 05:42:04 PDT 2006


Hello,

I wrote keyTouch (http://keytouch.sf.net) 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: 

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg/attachments/20060421/1ee6e516/attachment.html>


More information about the xorg mailing list