1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include <iostream>
#include <unistd.h>
#include <X11/Xlib.h>
using namespace std;
void click ( unsigned int button )
{
Display * display = XOpenDisplay(NULL);
XEvent event;
// Set click event structure
event.xbutton.same_screen = True;
event.xbutton.button = button;
// Get info about current pointer status
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
);
event.xbutton.subwindow = event.xbutton.window;
// Walk down through window hierachy to find youngest child
while ( event.xbutton.subwindow )
{
event.xbutton.window = event.xbutton.subwindow;
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
);
}
// Send ButtonPress event to youngest child
event.type = ButtonPress;
if ( XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0 )
{
cerr << "XSendEvent Failed !" << endl;
}
XFlush(display);
// Send ButtonRelease event to youngest child
event.type = ButtonRelease;
if ( XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0 )
{
cerr << "XSenderEvent Failed !" << endl;
}
XFlush(display);
// Close display
XCloseDisplay ( display );
}
int main ( int argc, char ** argv )
{
cout << "Clic gauche." << endl;
click(Button1); // -> clic gauche
getchar();
cout << "Clic molette." << endl;
click(Button2); // -> clic molette
getchar();
cout << "Clic droit." << endl;
click(Button3); // -> RIEN !
getchar();
cout << "Molette haut." << endl;
click(Button4); // -> molette haut
getchar();
cout << "Molette bas." << endl;
click(Button5); // -> molette bas
return 0;
} |
Partager