Add: add mac special click support

This commit is contained in:
vcaesar 2026-01-18 06:30:33 -08:00
parent 4c439be11f
commit 59e4b3007c
2 changed files with 15 additions and 10 deletions

View file

@ -201,7 +201,7 @@ int clickMouse(MMMouseButton button){
}
/* Special function for sending double clicks, needed for MacOS. */
int doubleClick(MMMouseButton button){
int doubleClick(MMMouseButton button, int count){
#if defined(IS_MACOSX)
/* Double click for Mac. */
const CGPoint currentPos = CGPointFromMMPointInt32(location());
@ -216,7 +216,7 @@ int doubleClick(MMMouseButton button){
}
/* Set event to double click. */
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
CGEventSetIntegerValueField(event, kCGMouseEventClickState, count);
CGEventPost(kCGHIDEventTap, event);
CGEventSetType(event, mouseTypeUP);

View file

@ -685,7 +685,7 @@ func ClickV1(args ...interface{}) {
if !double {
C.clickMouse(button)
} else {
C.doubleClick(button)
C.doubleClick(button, 2)
}
MilliSleep(MouseSleep)
@ -735,7 +735,7 @@ func Click(args ...interface{}) error {
return formatClickError(int(code), button, "up", count)
}
} else {
if code := C.doubleClick(button); code != 0 {
if code := C.doubleClick(button, 2); code != 0 {
return formatClickError(int(code), button, "double", 2)
}
}
@ -745,13 +745,18 @@ func Click(args ...interface{}) error {
// MultiClick performs multiple clicks and returns error
//
// robotgo.MultiClick(button string, count int)
func MultiClick(button string, count int) error {
func MultiClick(button string, count int, click ...bool) error {
if count < 1 {
return nil
}
btn := CheckMouse(button)
defer MilliSleep(MouseSleep)
if runtime.GOOS == "darwin" && len(click) <= 0 {
code := C.doubleClick(btn, C.int(count))
return formatClickError(int(code), btn, "down", count)
}
for i := 0; i < count; i++ {
if err := Click(btn, false, count); err != nil {
return err
@ -761,6 +766,9 @@ func MultiClick(button string, count int) error {
}
func formatClickError(code int, button C.MMMouseButton, stage string, count int) error {
if code == 0 {
return nil
}
btnName := MouseButtonString(button)
detail := ""
@ -840,15 +848,12 @@ func Toggle(key ...interface{}) error {
if len(key) > 1 && key[1].(string) == "up" {
down = false
}
code := C.toggleMouse(C.bool(down), button)
if code != 0 {
return formatClickError(int(code), button, "down", 1)
}
code := C.toggleMouse(C.bool(down), button)
if len(key) > 2 {
MilliSleep(MouseSleep)
}
return nil
return formatClickError(int(code), button, "down", 1)
}
// MouseDown send mouse down event