Advertisement
xerpi

xcb fake x11 linux

Jun 22nd, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <xcb/xcb.h>
  3. #include <xcb/xcb_keysyms.h>
  4. #include <xcb/xtest.h>
  5. #include <xcb/xcb_util.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8.  
  9.  
  10. /* xcb_test_fake_input(type,detail,time,window,x,y,device) */
  11. static void
  12. fake_input(xcb_connection_t *c, uint8_t type, uint8_t detail)
  13. {
  14.   xcb_window_t none = { XCB_NONE };
  15.  
  16.   xcb_test_fake_input( c, type, detail, 0, none, 0, 0, 0 );
  17. }
  18.  
  19. static void
  20. fake_motion(xcb_connection_t *c, uint8_t relative, uint16_t x, uint16_t y)
  21. {
  22.   xcb_window_t window = { XCB_NONE };
  23.  
  24.   if (!relative) {
  25.     window = xcb_setup_roots_iterator(xcb_get_setup(c)).data->root;
  26.   }
  27.   xcb_test_fake_input( c, XCB_MOTION_NOTIFY, relative, 0, window, x, y, 0 );
  28. }
  29.  
  30. void send_key( xcb_connection_t *c, char code ) {
  31.   fake_input( c, XCB_KEY_PRESS, code );
  32.   fake_input( c, XCB_KEY_RELEASE, code );
  33.  
  34. }
  35.  
  36. void mouse_click( xcb_connection_t *c, int button ) {
  37.   fake_input( c, XCB_BUTTON_PRESS, button );
  38.   fake_input( c, XCB_BUTTON_RELEASE, button );
  39. }
  40.  
  41. void mouse_move( xcb_connection_t *c, int x, int y ) {
  42.   fake_motion( c, 0, x, y );
  43. }
  44.  
  45. void mouse_rel_move( xcb_connection_t *c, int x, int y ) {
  46.   fake_motion( c, 1, x, y );
  47. }
  48.  
  49. void process_command( xcb_connection_t *c) {
  50. int x, y;
  51.     for(y = 0; y < 800; y+=20)
  52.     {
  53.         for(x = 0; x < 1280; x+=20)
  54.         {
  55.             mouse_move( c, x,y );
  56.             usleep(10000);
  57.             xcb_flush( c );
  58.         }
  59.     }
  60.    // fake_input( c, XCB_KEY_PRESS, 6);
  61.     //fake_input( c, XCB_KEY_RELEASE, 6 );
  62. }
  63.  
  64. int main( int argc, char *argv[] ) {
  65.     xcb_connection_t *c = NULL;
  66.     char *display = NULL;
  67.  
  68.     c = xcb_connect( display, NULL );
  69.     if( c == NULL ) {
  70.         fprintf( stderr, "Unable to open display '%s'\n", display == NULL ? "default" : display );
  71.         exit( 1 );
  72.     }
  73.  
  74.     process_command( c);
  75.  
  76.     xcb_disconnect( c );
  77.     exit( 0 );
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement