Skip to content
This repository was archived by the owner on Jun 19, 2021. It is now read-only.

Commit 014c722

Browse files
author
Simon Hofmann
committed
Enabled mouse button press on move
1 parent 910ab1d commit 014c722

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/mouse.c

+34-24
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,45 @@ void calculateDeltas(CGEventRef *event, MMPoint point)
9090
*/
9191
void moveMouse(MMPoint point)
9292
{
93-
#if defined(IS_MACOSX)
94-
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
95-
CGPointFromMMPoint(point),
96-
kCGMouseButtonLeft);
97-
98-
calculateDeltas(&move, point);
99-
100-
CGEventPost(kCGSessionEventTap, move);
101-
CFRelease(move);
102-
#elif defined(USE_X11)
93+
#ifdef USE_X11
10394
Display *display = XGetMainDisplay();
10495
XWarpPointer(display, None, DefaultRootWindow(display),
10596
0, 0, 0, 0, point.x, point.y);
10697
XSync(display, false);
107-
#elif defined(IS_WINDOWS)
108-
//Mouse motion is now done using SendInput with MOUSEINPUT. We use Absolute mouse positioning
109-
#define MOUSE_COORD_TO_ABS(coord, width_or_height) (((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
110-
point.x = MOUSE_COORD_TO_ABS(point.x, GetSystemMetrics(SM_CXSCREEN));
111-
point.y = MOUSE_COORD_TO_ABS(point.y, GetSystemMetrics(SM_CYSCREEN));
112-
INPUT mouseInput;
113-
mouseInput.type = INPUT_MOUSE;
114-
mouseInput.mi.dx = point.x;
115-
mouseInput.mi.dy = point.y;
116-
mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
117-
mouseInput.mi.time = 0; //System will provide the timestamp
118-
mouseInput.mi.dwExtraInfo = 0;
119-
mouseInput.mi.mouseData = 0;
120-
SendInput(1, &mouseInput, sizeof(mouseInput));
98+
#endif
99+
#ifdef IS_MACOSX
100+
CGPoint position = CGPointMake (point.x, point.y);
101+
// Create an HID hardware event source
102+
CGEventSourceRef src = CGEventSourceCreate
103+
(kCGEventSourceStateHIDSystemState);
104+
105+
CGEventRef evt = nullptr;
106+
if (CGEventSourceButtonState (kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft)) {
107+
// Create a left button drag
108+
evt = CGEventCreateMouseEvent
109+
(src, kCGEventLeftMouseDragged,
110+
position, kCGMouseButtonLeft);
111+
} else {
112+
if (CGEventSourceButtonState (kCGEventSourceStateHIDSystemState, kCGMouseButtonRight)) {
113+
// Create a right button drag
114+
evt = CGEventCreateMouseEvent
115+
(src, kCGEventRightMouseDragged,
116+
position, kCGMouseButtonLeft);
117+
} else {
118+
// Create a mouse move event
119+
evt = CGEventCreateMouseEvent
120+
(src, kCGEventMouseMoved,
121+
position, kCGMouseButtonLeft);
122+
}
123+
}
121124

125+
// Post mouse event and release
126+
CGEventPost (kCGHIDEventTap, evt);
127+
CFRelease (evt);
128+
CFRelease (src);
129+
#endif
130+
#ifdef IS_WINDOWS
131+
SetCursorPos (point.x, point.y);
122132
#endif
123133
}
124134

0 commit comments

Comments
 (0)