Skip to content

Commit f1afaab

Browse files
committed
Added doubleClick function.
1 parent ec1fd14 commit f1afaab

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/mouse.c

+40
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ void clickMouse(MMMouseButton button)
124124
toggleMouse(false, button);
125125
}
126126

127+
void doubleClick(MMMouseButton button)
128+
{
129+
130+
#if defined(IS_MACOSX)
131+
132+
/* Double click for Mac. */
133+
const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
134+
const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
135+
const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);
136+
137+
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);
138+
139+
/* Set event to double click. */
140+
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
141+
142+
CGEventPost(kCGHIDEventTap, event);
143+
144+
CGEventSetType(event, mouseTypeUP);
145+
CGEventPost(kCGHIDEventTap, event);
146+
147+
CFRelease(event);
148+
149+
#elif defined(IS_WINDOWS)
150+
151+
/* Double click for Windows. */
152+
clickMouse(button);
153+
/* TODO: Use GetDoubleClickTime to retrieve the current double click time. */
154+
microsleep(500);
155+
clickMouse(button);
156+
157+
#else
158+
159+
/* Double click for everything else. */
160+
clickMouse(button);
161+
microsleep(500);
162+
clickMouse(button);
163+
164+
#endif
165+
}
166+
127167
/*
128168
* A crude, fast hypot() approximation to get around the fact that hypot() is
129169
* not a standard ANSI C function.

src/mouse.h

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ void toggleMouse(bool down, MMMouseButton button);
7373
/* Clicks the mouse with the given button in the current position. */
7474
void clickMouse(MMMouseButton button);
7575

76+
/* Double clicks the mouse with the given button. */
77+
void doubleClick(MMMouseButton button);
78+
7679
#endif /* MOUSE_H */
7780

7881
#ifdef __cplusplus

0 commit comments

Comments
 (0)