Generating synthetic events in X
Both HandwritingRecognition and VirtualKeyboards need some sort of mechanism to send synthetic events to a window. In X, this can be done in two different ways:
-
XTestFakeKeyEvent (part of the XTest extension)
When I asked which method is preferred, all answers I received favor XTest over XSendEvent. Here are some replies:
From JimGettys::
-
Events sent via XSendEvent are tagged to allow programs to detect they are synthesized input.
Terminal emulators generally ignore keyboard events so tagged, or I'd have a trivial way to break security (since I could synthesize input to your shell so trivially).
The XTest extension allows an application to synthesize input indistinguishable from real input, with a slight modicum of security (requiring the application to run locally, for example).
From KeithPackard::
-
Use XTEST; XSendEvent doesn't go through the same paths as a "real" keyboard and can have funny effects.
NB: I've found this to be very true. For example, using XTestFakeKeyEvent, any modifier keys that are currently pressed will "just work". With XSendEvent you would have to somehow query the modifiers manually and set the bits. - CarlWorth
In addition, I wrote a program twice using each of these methods. I found that XTestFakeKeyEvent was much easier to use than XSendEvent.