19
19
#include " notimplementedexception.h"
20
20
#include < iostream>
21
21
22
+ // memset
23
+ #include < stdio.h>
24
+ #include < cstring>
25
+
26
+ // sleep
27
+ #include < chrono>
28
+ #include < thread>
29
+
22
30
XInputSimulatorImplLinux::XInputSimulatorImplLinux ()
23
31
{
24
32
if ((display = XOpenDisplay (NULL )) == NULL ) {
@@ -29,6 +37,22 @@ XInputSimulatorImplLinux::XInputSimulatorImplLinux()
29
37
root = DefaultRootWindow (display);
30
38
}
31
39
40
+ void XInputSimulatorImplLinux::initMouseEvent (int button)
41
+ {
42
+ event.xbutton .button = button; // which button
43
+ event.xbutton .same_screen = True;
44
+ event.xbutton .subwindow = DefaultRootWindow (display);
45
+ while (event.xbutton .subwindow )
46
+ {
47
+ event.xbutton .window = event.xbutton .subwindow ;
48
+ XQueryPointer (display, event.xbutton .window ,
49
+ &event.xbutton .root , &event.xbutton .subwindow ,
50
+ &event.xbutton .x_root , &event.xbutton .y_root ,
51
+ &event.xbutton .x , &event.xbutton .y ,
52
+ &event.xbutton .state );
53
+ }
54
+ }
55
+
32
56
void XInputSimulatorImplLinux::mouseMoveTo (int x, int y)
33
57
{
34
58
std::cout << " move the mouse!\n " ;
@@ -39,6 +63,10 @@ void XInputSimulatorImplLinux::mouseMoveTo(int x, int y)
39
63
40
64
XWarpPointer (display, None, root, 0 , 0 , 0 , 0 , x, y);
41
65
XFlush (display);
66
+
67
+
68
+ XEvent event;
69
+ memset (&event, 0 , sizeof (event));
42
70
}
43
71
44
72
void XInputSimulatorImplLinux::mouseMoveRelative (int x, int y)
@@ -55,17 +83,34 @@ void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
55
83
56
84
void XInputSimulatorImplLinux::mouseDown (int button)
57
85
{
58
- throw NotImplementedException ();
86
+ // throw NotImplementedException();
87
+
88
+ this ->initMouseEvent (button);
89
+
90
+ event.type = ButtonPress;
91
+ if (XSendEvent (display, PointerWindow, True, ButtonPressMask, &event) == 0 )
92
+ std::cout << " Error to send the event!\n " ;
93
+ XFlush (display);
59
94
}
60
95
61
96
void XInputSimulatorImplLinux::mouseUp (int button)
62
97
{
63
- throw NotImplementedException ();
98
+ // throw NotImplementedException();
99
+
100
+ this ->initMouseEvent (button);
101
+
102
+ event.type = ButtonRelease;
103
+ if (XSendEvent (display, PointerWindow, True, ButtonReleaseMask, &event) == 0 )
104
+ std::cout << " Error to send the event!\n " ;
105
+ XFlush (display);
64
106
}
65
107
66
108
void XInputSimulatorImplLinux::mouseClick (int button)
67
109
{
68
- throw NotImplementedException ();
110
+ // throw NotImplementedException();
111
+ this ->mouseDown (button);
112
+ std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
113
+ this ->mouseUp (button);
69
114
}
70
115
71
116
void XInputSimulatorImplLinux::mouseScrollX (int length)
0 commit comments