Difference between revisions of "Tutorials/C Programming Tutorial/How to simulate a keypress"

From ThorstensHome
Jump to: navigation, search

Revision as of 16:34, 10 May 2009

The following program simulates the keypress of NUMLOCK in your session of the X Windowing System.

#include <X11/extensions/XTest.h>
#include <X11/keysym.h>

/* Compile this using
g++ -lXtst main.cpp
*/

int main()
{
  Display* display= XOpenDisplay(NULL);
  XTestFakeKeyEvent(display, XKeysymToKeycode( display, XK_Num_Lock ), true, CurrentTime);
  XTestFakeKeyEvent(display, XKeysymToKeycode( display, XK_Num_Lock ), false, CurrentTime);
  XCloseDisplay( display );
}