Simulate keyboard events on Linux2010年10月5日
High level GUI Library/Framework(like QT, GTK+) make it easier to develop GUI programs in Linux. But both of them are lack of some features because their design purpose.
So it seems, I have no thing to do unless programming with Xlib if i want to to simulate keyboard events.
Fortunately, I got XTest(the X test extension), a library to test X11 server without user intervention, which can be used to simulate mouse and keyboard events in three ways.
To use it, as easy as doing simulation in MS Windows(SendMessage() with KEY_PRESS Message). Examine X11/extensions/XTest.h for more details. And this article explain the functions and arguments of XTest.
There is a more convenient approach to fake keyboard event for python users, just like me :). It's virtkey, python extension for emulating keypresses and getting current keyboard layout. In fact, this package is a wrapper for most used functions in XTest, but only keyboard simulation.
Whether it's used as a part of a program or just some automatic test-cases for GUI programs, are not bad. The virtual keyboard in Ubuntu, OnBoard, written with it.