Posted By


whitetiger on 11/09/06

Statistics


Viewed 1211 times
Favorited by 2 user(s)

Xlib - mouseClick


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <unistd.h>
  6.  
  7. #include <X11/Xlib.h>
  8. #include <X11/Xutil.h>
  9.  
  10. void mouseClick(int button)
  11. {
  12. Display *display = XOpenDisplay(NULL);
  13.  
  14. XEvent event;
  15.  
  16. if(display == NULL)
  17. {
  18. fprintf(stderr, "Errore nell'apertura del Display !!!\n");
  19. exit(EXIT_FAILURE);
  20. }
  21.  
  22. memset(&event, 0x00, sizeof(event));
  23.  
  24. event.type = ButtonPress;
  25. event.xbutton.button = button;
  26. event.xbutton.same_screen = True;
  27.  
  28. XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
  29.  
  30. event.xbutton.subwindow = event.xbutton.window;
  31.  
  32. while(event.xbutton.subwindow)
  33. {
  34. event.xbutton.window = event.xbutton.subwindow;
  35.  
  36. XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
  37. }
  38.  
  39. if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");
  40.  
  41. XFlush(display);
  42.  
  43. usleep(100000);
  44.  
  45. event.type = ButtonRelease;
  46. event.xbutton.state = 0x100;
  47.  
  48. if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");
  49.  
  50. XFlush(display);
  51.  
  52. XCloseDisplay(display);
  53. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.