Skip to content

Add: add toogle error check and MultiClikck, optimize the code and api#757

Merged
vcaesar merged 4 commits intomasterfrom
bitmap-pr
Jan 18, 2026
Merged

Add: add toogle error check and MultiClikck, optimize the code and api#757
vcaesar merged 4 commits intomasterfrom
bitmap-pr

Conversation

@vcaesar
Copy link
Member

@vcaesar vcaesar commented Jan 18, 2026

Please provide Issues links to:

  • Issues: #

Provide test code:

Description

...

Summary by CodeRabbit

  • New Features

    • Added multi-click capability and a repeat/count parameter for click operations.
  • Refactor

    • Standardized public mouse-action names for consistency.
    • Internal click and toggle flows updated to use the new, simplified interfaces.
  • Bug Fixes

    • Improved input validation and clearer count-based error reporting.
  • Documentation

    • Updated public docs/comments to reflect new signatures and behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 18, 2026 14:23
@gemini-code-assist
Copy link

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2026

Warning

Rate limit exceeded

@vcaesar has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 96fac4f and dc03345.

📒 Files selected for processing (1)
  • robotgo.go

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Renames C mouse API functions to drop "Err" suffixes, extends double-click to accept a count, and updates Go APIs: introduces ClickV1 and MultiClick, replaces ClickE with a new Click that accepts count and returns error, and changes error formatting to include count.

Changes

Cohort / File(s) Summary
C Mouse API
mouse/mouse_c.h
Renamed exported functions: toggleMouseErrtoggleMouse, clickMouseErrclickMouse, doubleClickErrdoubleClick; updated internal call sites and added count handling for double-click on macOS.
Go Click API
robotgo.go
Reworked click APIs: added ClickV1 and MultiClick(button string, count int, click ...bool) error; replaced ClickE with Click(args ...interface{}) error that accepts a count; updated formatClickError to use count; adjusted flows to call C.toggleMouse/C.clickMouse and propagate count-based error messages.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client as Client
    participant Go as Go (robotgo.go)
    participant C as C shim (mouse/mouse_c.h)
    participant OS as OS (macOS / Other)
    Client->>Go: Call Click/ClickV1/MultiClick(args...)
    Go->>Go: validate args, determine button & count
    Go->>C: C.toggleMouse(down, button)
    C->>OS: perform mouse down
    OS-->>C: result code
    C-->>Go: return code
    Go->>Go: optional delay based on count
    Go->>C: C.toggleMouse(up, button)
    C->>OS: perform mouse up
    OS-->>C: result code
    C-->>Go: return code
    Go-->>Client: return error if any (includes count in message)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 A hop, a click, a counted double-tap,
I renamed and tidied every mouse-wrap,
ClickV1 and MultiClick led the dance,
C names shortened gave code a chance,
I nibble bugs, then bound off with a clap!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete: it contains only template placeholders with no issue links provided, empty test code block, and no substantive description of changes or rationale. Fill in the empty sections: provide relevant issue link(s), include test code demonstrating the new MultiClick and updated click APIs, and add a detailed description of the changes and their purpose.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title mentions adding toggle error checks and MultiClick, and optimizing the API, which aligns with the main changes (renaming error-handling functions and adding MultiClick functionality).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the mouse clicking API by consolidating error handling, adding a new MultiClick function, and simplifying the C code. The main Click function now returns errors (replacing ClickE), the old version is preserved as ClickV1, and several C wrapper functions have been removed in favor of direct error-returning implementations.

Changes:

  • Renamed Click to ClickV1 and ClickE to Click to make error-returning the default behavior
  • Added MultiClick function for performing multiple consecutive clicks
  • Updated C functions to remove non-error-returning wrappers (toggleMouse, clickMouse, doubleClick now return errors directly)
  • Added error handling to the Toggle function
  • Changed error messages from "double=bool" format to "count=int" format

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
robotgo.go Refactors Click API to return errors by default, adds MultiClick function, updates Toggle with error handling
mouse/mouse_c.h Removes wrapper functions and consolidates error handling in C code, includes minor formatting cleanup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

robotgo.go Outdated
defer MilliSleep(MouseSleep)

for i := 0; i < count; i++ {
if err := Click(btn, false, count); err != nil {
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MultiClick function passes the total count value as the third argument to Click, but this is incorrect. The Click function's signature is Click(button string, double bool, ...), so the third argument would be interpreted as something else (and based on line 724-726, it's trying to access args[3] for count). This will result in incorrect behavior. The count parameter in Click appears to be meant for error reporting only, not as a loop counter. Remove the count parameter from this Click call.

Suggested change
if err := Click(btn, false, count); err != nil {
if err := Click(btn, false); err != nil {

Copilot uses AI. Check for mistakes.
robotgo.go Outdated
C.toggleMouse(C.bool(down), button)
code := C.toggleMouse(C.bool(down), button)
if code != 0 {
return formatClickError(int(code), button, "down", 1)
Copy link

Copilot AI Jan 18, 2026

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.

Suggested change
return formatClickError(int(code), button, "down", 1)
stage := "down"
if !down {
stage = "up"
}
return formatClickError(int(code), button, stage, 1)

Copilot uses AI. Check for mistakes.
Comment on lines +694 to +702
// 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 {
Copy link

Copilot AI Jan 18, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
robotgo.go (2)

702-742: Fix count indexing + type validation to avoid silent 0 and panics.
count is read from args[3], so a 3‑arg call never sets it, and the unchecked cast can panic. Also, defaulting to 0 makes error messages misleading for single clicks.

🛠️ Suggested fix
-		count  int
+		count  = 1
 	)
@@
-	if len(args) > 3 {
-		count = args[3].(int)
-	}
+	if len(args) > 2 {
+		c, ok := args[2].(int)
+		if !ok {
+			return errors.New("third argument must be click count (int)")
+		}
+		count = c
+	}

833-846: Use the correct stage label for Toggle errors.
On an “up” toggle, the error message still reports down, which is misleading.

🛠️ Suggested fix
-	code := C.toggleMouse(C.bool(down), button)
+	stage := "down"
+	if !down {
+		stage = "up"
+	}
+	code := C.toggleMouse(C.bool(down), button)
 	if code != 0 {
-		return formatClickError(int(code), button, "down", 1)
+		return formatClickError(int(code), button, stage, 1)
 	}
🤖 Fix all issues with AI agents
In `@robotgo.go`:
- Around line 745-759: MultiClick is passing the result of CheckMouse (a
C.MMMouseButton) into Click, causing a type mismatch; change the call to use the
original button string instead (keep calling CheckMouse(button) to
validate/prepare the button but pass button to Click), i.e. update the Click
invocation inside MultiClick to pass the string first argument; refer to
function names MultiClick, CheckMouse and Click when locating and fixing the
call.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mouse/mouse_c.h (1)

203-236: count parameter ignored on non-macOS platforms.

The count parameter is only used on macOS (line 219) to set kCGMouseEventClickState. On Windows and Linux (lines 229-236), the function always performs exactly 2 clicks regardless of the count value passed. This breaks the MultiClick functionality on non-macOS platforms.

🐛 Proposed fix to honor count on all platforms
 	`#else`
 		/* Double click for everything else. */
-		int err = clickMouse(button);
-		if (err != 0) {
-			return err;
+		for (int i = 0; i < count; i++) {
+			int err = clickMouse(button);
+			if (err != 0) {
+				return err;
+			}
+			if (i < count - 1) {
+				microsleep(200);
+			}
 		}
-		microsleep(200);
-		return clickMouse(button);
+		return 0;
 	`#endif`
🤖 Fix all issues with AI agents
In `@robotgo.go`:
- Around line 724-726: The code unsafely reads count via args[3] without a type
check and also skips args[2], which is confusing and can panic; update the
handler that sets count to (1) use the intended parameter index (either args[2]
if count is the 3rd arg or keep args[3] but then document why) and (2) perform a
safe type assertion (use a type switch or v, ok := args[index].(int) and
fallback/default if !ok) before assigning to the count variable; also update or
add documentation near the existing comment block that describes the parameter
position and expected type so callers aren’t surprised.
♻️ Duplicate comments (2)
robotgo.go (2)

760-764: MultiClick passes wrong type to Click (still broken).

Click(btn, false, count) passes btn which is C.MMMouseButton, but Click expects a string as the first argument. This will always return "first argument must be a button string".

🐛 Proposed fix
 	for i := 0; i < count; i++ {
-		if err := Click(btn, false, count); err != nil {
+		if err := Click(button, false); err != nil {
 			return err
 		}
 	}

851-857: Error stage hardcoded to "down" even for mouse-up actions.

When down is false, the error message will incorrectly report "click down failed" instead of "click up failed". This was flagged in a previous review.

🐛 Proposed fix
+	stage := "down"
+	if !down {
+		stage = "up"
+	}
 	code := C.toggleMouse(C.bool(down), button)
 	if len(key) > 2 {
 		MilliSleep(MouseSleep)
 	}
-	return formatClickError(int(code), button, "down", 1)
+	return formatClickError(int(code), button, stage, 1)
🧹 Nitpick comments (1)
robotgo.go (1)

755-758: Consider returning nil explicitly on success for clarity.

The current code works because formatClickError returns nil when code == 0, but the intent would be clearer with an explicit success check.

♻️ Optional refactor for clarity
 	if runtime.GOOS == "darwin" && len(click) <= 0 {
 		code := C.doubleClick(btn, C.int(count))
+		if code == 0 {
+			return nil
+		}
 		return formatClickError(int(code), btn, "down", count)
 	}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vcaesar vcaesar added this to the v1.10.0 milestone Jan 18, 2026
@vcaesar vcaesar merged commit cec382b into master Jan 18, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments