-
Notifications
You must be signed in to change notification settings - Fork 947
Add: add toogle error check and MultiClikck, optimize the code and api #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -659,7 +659,7 @@ func Location() (int, int) { | |||||||||||||
| return x, y | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Click click the mouse button | ||||||||||||||
| // ClickV1 click the mouse button | ||||||||||||||
| // | ||||||||||||||
| // robotgo.Click(button string, double bool) | ||||||||||||||
| // | ||||||||||||||
|
|
@@ -668,7 +668,7 @@ func Location() (int, int) { | |||||||||||||
| // robotgo.Click() // default is left button | ||||||||||||||
| // robotgo.Click("right") | ||||||||||||||
| // robotgo.Click("wheelLeft") | ||||||||||||||
| func Click(args ...interface{}) { | ||||||||||||||
| func ClickV1(args ...interface{}) { | ||||||||||||||
| var ( | ||||||||||||||
| button C.MMMouseButton = C.LEFT_BUTTON | ||||||||||||||
| double bool | ||||||||||||||
|
|
@@ -691,18 +691,19 @@ func Click(args ...interface{}) { | |||||||||||||
| MilliSleep(MouseSleep) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // ClickE click the mouse button and return error | ||||||||||||||
| // Click click the mouse button and return error | ||||||||||||||
| // | ||||||||||||||
| // robotgo.ClickE(button string, double bool) | ||||||||||||||
| // robotgo.Click(button string, double bool) | ||||||||||||||
| // | ||||||||||||||
| // Examples: | ||||||||||||||
| // | ||||||||||||||
| // err := robotgo.ClickE() // default is left button | ||||||||||||||
| // err := robotgo.ClickE("right") | ||||||||||||||
| func ClickE(args ...interface{}) error { | ||||||||||||||
| // err := robotgo.Click() // default is left button | ||||||||||||||
| // err := robotgo.Click("right") | ||||||||||||||
| func Click(args ...interface{}) error { | ||||||||||||||
| var ( | ||||||||||||||
| button C.MMMouseButton = C.LEFT_BUTTON | ||||||||||||||
| double bool | ||||||||||||||
| count int | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| if len(args) > 0 { | ||||||||||||||
|
|
@@ -720,30 +721,46 @@ func ClickE(args ...interface{}) error { | |||||||||||||
| } | ||||||||||||||
| double = dbl | ||||||||||||||
| } | ||||||||||||||
| if len(args) > 3 { | ||||||||||||||
| count = args[3].(int) | ||||||||||||||
| } | ||||||||||||||
vcaesar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
|
|
||||||||||||||
| defer MilliSleep(MouseSleep) | ||||||||||||||
|
|
||||||||||||||
| if !double { | ||||||||||||||
| if code := C.toggleMouseErr(true, button); code != 0 { | ||||||||||||||
| return formatClickError(int(code), button, "down", false) | ||||||||||||||
| if code := C.toggleMouse(true, button); code != 0 { | ||||||||||||||
| return formatClickError(int(code), button, "down", count) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // match clickMouse timing | ||||||||||||||
| C.microsleep(C.double(5.0)) | ||||||||||||||
|
|
||||||||||||||
| if code := C.toggleMouseErr(false, button); code != 0 { | ||||||||||||||
| return formatClickError(int(code), button, "up", false) | ||||||||||||||
| MilliSleep(5) | ||||||||||||||
| if code := C.toggleMouse(false, button); code != 0 { | ||||||||||||||
| return formatClickError(int(code), button, "up", count) | ||||||||||||||
| } | ||||||||||||||
| } else { | ||||||||||||||
| if code := C.doubleClickErr(button); code != 0 { | ||||||||||||||
| return formatClickError(int(code), button, "double", true) | ||||||||||||||
| if code := C.doubleClick(button); code != 0 { | ||||||||||||||
| return formatClickError(int(code), button, "double", 2) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| return nil | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // MultiClick performs multiple clicks and returns error | ||||||||||||||
| // | ||||||||||||||
| // robotgo.MultiClick(button string, count int) | ||||||||||||||
| func MultiClick(button string, count int) error { | ||||||||||||||
| if count < 1 { | ||||||||||||||
| return nil | ||||||||||||||
| } | ||||||||||||||
| btn := CheckMouse(button) | ||||||||||||||
| defer MilliSleep(MouseSleep) | ||||||||||||||
|
|
||||||||||||||
| for i := 0; i < count; i++ { | ||||||||||||||
| if err := Click(btn, false, count); err != nil { | ||||||||||||||
|
||||||||||||||
| if err := Click(btn, false, count); err != nil { | |
| if err := Click(btn, false); err != nil { |
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error stage is hardcoded to "down" even when the down parameter is false (indicating an "up" action). This will produce misleading error messages when a mouse up operation fails. The stage should be set to "up" when down is false.
| return formatClickError(int(code), button, "down", 1) | |
| stage := "down" | |
| if !down { | |
| stage = "up" | |
| } | |
| return formatClickError(int(code), button, stage, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Click function signature in the documentation comment still references the old API with (button string, double bool), but the actual implementation now supports an additional count parameter at args[3]. The documentation should be updated to reflect the new signature or the count parameter implementation should be reconsidered since it appears incomplete.