1818 #define M_SQRT2 1.4142135623730950488016887 /* Fix for MSVC. */
1919#endif
2020
21+ /* Some convenience macros for converting our enums to the system API types. */
22+ #if defined(IS_MACOSX )
23+
24+ #define MMMouseToCGEventType (down , button ) \
25+ (down ? MMMouseDownToCGEventType(button) : MMMouseUpToCGEventType(button))
26+
27+ #define MMMouseDownToCGEventType (button ) \
28+ ((button) == (LEFT_BUTTON) ? kCGEventLeftMouseDown \
29+ : ((button) == RIGHT_BUTTON ? kCGEventRightMouseDown \
30+ : kCGEventOtherMouseDown))
31+
32+ #define MMMouseUpToCGEventType (button ) \
33+ ((button) == LEFT_BUTTON ? kCGEventLeftMouseUp \
34+ : ((button) == RIGHT_BUTTON ? kCGEventRightMouseUp \
35+ : kCGEventOtherMouseUp))
36+
37+ #define MMMouseDragToCGEventType (button ) \
38+ ((button) == LEFT_BUTTON ? kCGEventLeftMouseDragged \
39+ : ((button) == RIGHT_BUTTON ? kCGEventRightMouseDragged \
40+ : kCGEventOtherMouseDragged))
41+
42+ #elif defined(IS_WINDOWS )
43+
44+ #define MMMouseToMEventF (down , button ) \
45+ (down ? MMMouseDownToMEventF(button) : MMMouseUpToMEventF(button))
46+
47+ #define MMMouseUpToMEventF (button ) \
48+ ((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTUP \
49+ : ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTUP \
50+ : MOUSEEVENTF_MIDDLEUP))
51+
52+ #define MMMouseDownToMEventF (button ) \
53+ ((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTDOWN \
54+ : ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTDOWN \
55+ : MOUSEEVENTF_MIDDLEDOWN))
56+
57+ #endif
58+
2159/**
2260 * Move the mouse to a specific point.
2361 * @param point The coordinates to move the mouse to (x, y).
@@ -44,6 +82,20 @@ void moveMouse(MMPoint point)
4482#endif
4583}
4684
85+ void dragMouse (MMPoint point , const MMMouseButton button )
86+ {
87+ #if defined(IS_MACOSX )
88+ const CGEventType dragType = MMMouseDragToCGEventType (button );
89+ const CGEventRef drag = CGEventCreateMouseEvent (NULL , dragType ,
90+ CGPointFromMMPoint (point ),
91+ (CGMouseButton )button );
92+ CGEventPost (kCGSessionEventTap , drag );
93+ CFRelease (drag );
94+ #else
95+ moveMouse (point );
96+ #endif
97+ }
98+
4799MMPoint getMousePos ()
48100{
49101#if defined(IS_MACOSX )
@@ -71,39 +123,6 @@ MMPoint getMousePos()
71123#endif
72124}
73125
74- /* Some convenience macros for converting our enums to the system API types. */
75- #if defined(IS_MACOSX )
76-
77- #define MMMouseToCGEventType (down , button ) \
78- (down ? MMMouseDownToCGEventType(button) : MMMouseUpToCGEventType(button))
79-
80- #define MMMouseDownToCGEventType (button ) \
81- ((button) == (LEFT_BUTTON) ? kCGEventLeftMouseDown \
82- : ((button) == RIGHT_BUTTON ? kCGEventRightMouseDown \
83- : kCGEventOtherMouseDown))
84-
85- #define MMMouseUpToCGEventType (button ) \
86- ((button) == LEFT_BUTTON ? kCGEventLeftMouseUp \
87- : ((button) == RIGHT_BUTTON ? kCGEventRightMouseUp \
88- : kCGEventOtherMouseUp))
89-
90- #elif defined(IS_WINDOWS )
91-
92- #define MMMouseToMEventF (down , button ) \
93- (down ? MMMouseDownToMEventF(button) : MMMouseUpToMEventF(button))
94-
95- #define MMMouseUpToMEventF (button ) \
96- ((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTUP \
97- : ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTUP \
98- : MOUSEEVENTF_MIDDLEUP))
99-
100- #define MMMouseDownToMEventF (button ) \
101- ((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTDOWN \
102- : ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTDOWN \
103- : MOUSEEVENTF_MIDDLEDOWN))
104-
105- #endif
106-
107126/**
108127 * Press down a button, or release it.
109128 * @param down True for down, false for up.
0 commit comments