XBMCMove 1.0
Controlar o XBMC com gestos

teclado.cpp

Go to the documentation of this file.
00001 #include "teclado.h"
00002 
00003 teclado::teclado(){
00004     
00005 }
00006 
00007 teclado::~teclado(){
00008     
00009 }
00010 
00011 XKeyEvent teclado::createKeyEvent(Display *display, Window &win, Window &winRoot, bool press, int keycode, int modifiers) {
00012     XKeyEvent event;
00013 
00014     event.display = display;
00015     event.window = win;
00016     event.root = winRoot;
00017     event.subwindow = None;
00018     event.time = CurrentTime;
00019     event.x = 1;
00020     event.y = 1;
00021     event.x_root = 1;
00022     event.y_root = 1;
00023     event.same_screen = True;
00024     event.keycode = XKeysymToKeycode(display, keycode);
00025     event.state = modifiers;
00026 
00027     if (press)
00028         event.type = KeyPress;
00029     else
00030         event.type = KeyRelease;
00031 
00032     return event;
00033 }
00034 
00035 void teclado::simular(int tecla){
00036     // Obtain the X11 display.
00037     Display *display = XOpenDisplay(0);
00038 
00039     // Get the root window for the current display.
00040     Window winRoot = XDefaultRootWindow(display);
00041 
00042     // Find the window which has the current keyboard focus.
00043     Window winFocus;
00044     int revert;
00045     XGetInputFocus(display, &winFocus, &revert);
00046 
00047     // Send a fake key press event to the window.
00048     XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, tecla, 0);
00049     XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *) & event);
00050 
00051     // Send a fake key release event to the window.
00052     event = createKeyEvent(display, winFocus, winRoot, false, tecla, 0);
00053     XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *) & event);
00054 
00055     // Done.
00056     XCloseDisplay(display);
00057 }
 All Classes Files Functions Variables Defines