interface MouseAPI {
    GetPos(): MousePosition;
    Move(x: number, y: number, smooth?: boolean): void;
    Click(button?: MouseClickButton, clicks?: number): void;
    Down(button?: MouseClickButton): void;
    Up(button?: MouseClickButton): void;
    Drag(startX: number, startY: number, endX: number, endY: number): void;
    Scroll(lines: number): void;
    OnRawEvent(callback: (event: RawMouseEvent) => void): void;
    OnButton(
        combo: string,
        callback: () => void,
        options?: MouseButtonOptions,
    ): void;
    OnDown(
        combo: string,
        callback: () => void,
        options?: MouseButtonOptions,
    ): void;
    OnUp(
        combo: string,
        callback: () => void,
        options?: MouseButtonOptions,
    ): void;
}

Methods

  • Returns the current cursor position in screen pixel coordinates.

    Returns MousePosition

    const { x, y } = Mouse.GetPos();
    Console.Log(`Cursor at ${x}, ${y}`);
  • Moves the cursor to the specified screen coordinates.

    Parameters

    • x: number

      Target X position in pixels.

    • y: number

      Target Y position in pixels.

    • Optionalsmooth: boolean

      When true, the cursor glides to the target over ~100 ms. Defaults to false.

    Returns void

    Mouse.Move(960, 540);        // instant warp to center
    Mouse.Move(960, 540, true); // smooth glide over ~100ms

    mouse

  • Injects a complete button press-and-release at the current cursor position. Sends both the DOWN and UP events as a matched pair. To inject only the DOWN or only the UP, use Mouse.Down and Mouse.Up instead.

    Parameters

    • Optionalbutton: MouseClickButton

      Which button to click. Defaults to "left".

    • Optionalclicks: number

      Number of consecutive clicks. Defaults to 1. Use 2 for double-click.

    Returns void

    Mouse.Click();             // left click
    Mouse.Click("right"); // right click
    Mouse.Click("left", 2); // double-click

    mouse

  • Injects a button-down (press) event without a matching release. Use Mouse.Up with the same button to release it. Useful for simulating held button states or custom drag sequences.

    Parameters

    • Optionalbutton: MouseClickButton

      Button to press: "left", "right", "middle", "x1", "x2". Defaults to "left".

    Returns void

    Mouse.Down("left");   // press and hold left button
    // ... do work ...
    Mouse.Up("left"); // release

    mouse

  • Injects a button-up (release) event without a preceding press. Intended to pair with a prior Mouse.Down call.

    Parameters

    • Optionalbutton: MouseClickButton

      Button to release: "left", "right", "middle", "x1", "x2". Defaults to "left".

    Returns void

    Mouse.Down("left");
    // ... do work ...
    Mouse.Up("left");

    mouse

  • Performs a mouse drag operation (left button) from one point to another. The cursor is moved to the start position, the button is pressed, the cursor glides to the end position, then the button is released.

    Parameters

    • startX: number

      Starting X position in pixels.

    • startY: number

      Starting Y position in pixels.

    • endX: number

      Ending X position in pixels.

    • endY: number

      Ending Y position in pixels.

    Returns void

    Mouse.Drag(100, 200, 400, 200); // drag horizontally
    

    mouse

  • Scrolls the mouse wheel at the current cursor position.

    Parameters

    • lines: number

      Number of lines to scroll. Positive values scroll up, negative scroll down.

    Returns void

    Mouse.Scroll(3);  // scroll up 3 lines
    Mouse.Scroll(-3); // scroll down 3 lines

    mouse

  • Registers a callback that fires on every raw mouse event. The script enters an event loop and stays alive as long as this handler is registered.

    Parameters

    • callback: (event: RawMouseEvent) => void

      Handler receiving a RawMouseEvent for each mouse event.

    Returns void

    USE CASE: Per-device mouse filtering using event.device_id, or reacting to specific button flags without using a hotkey binding.

    Mouse.OnRawEvent((e) => {
    Console.Log("flags: " + e.button_flags);
    });

    mouse

  • Registers a callback that fires when a mouse button is pressed down, optionally requiring modifier keys to be held at the same time.

    Combo format: optional modifier tokens joined with +, with the button name last. Either-side modifiers: Ctrl, Shift, Alt, Win. Lateral modifiers: LCtrl, RCtrl, LShift, RShift, LAlt, RAlt, LWin, RWin.

    Button names (case-insensitive): LButton, RButton, MButton, XButton1, XButton2. Long aliases LeftButton, RightButton, MiddleButton, Mouse4, Mouse5 are also accepted.

    Blocking (default block: true): Both the button-down and its paired button-up are suppressed from reaching other applications. The modifier keys themselves are not suppressed. Use Keyboard.Press to send any needed cleanup. Set block: false to observe the click while passing it through.

    Parameters

    • combo: string

      Button combination string, e.g. "LButton", "Shift+LButton", "Ctrl+Alt+RButton".

    • callback: () => void

      Function invoked when the combo fires (on button-down).

    • Optionaloptions: MouseButtonOptions

      Optional configuration. See MouseButtonOptions for details.

    Returns void

    // Intercept Shift+LButton
    Mouse.OnButton("Shift+LButton", () => {
    Console.Log("shift-clicked at", Mouse.GetPos());
    });

    // Non-blocking observe-only
    Mouse.OnButton("Ctrl+RButton", () => {
    Console.Log("ctrl right-click");
    }, { block: false });

    mouse

  • Registers a callback that fires when a mouse button is pressed down, identical in behavior to Mouse.OnButton.

    Use this when you want to be explicit that you are reacting to the press phase and may also register an OnUp handler for the release phase.

    Button names and modifiers: same as Mouse.OnButton. Blocking: same as Mouse.OnButton, both down and its paired up are suppressed when block: true (default).

    Parameters

    • combo: string

      Button combination string, e.g. "LButton", "Shift+LButton".

    • callback: () => void

      Function invoked on button-down.

    • Optionaloptions: MouseButtonOptions

      Optional configuration. See MouseButtonOptions for details.

    Returns void

    let heldAt = 0;
    Mouse.OnDown("XButton1", () => { heldAt = Date.now(); });
    Mouse.OnUp("XButton1", () => {
    Console.Log("held for " + (Date.now() - heldAt) + "ms");
    });

    mouse

  • Registers a callback that fires when a mouse button is released.

    Button names and modifiers: same as Mouse.OnButton.

    Blocking: defaults to false. Set block: true in options to also suppress the button-up event from reaching other applications.

    Pairing with OnDown: When a button-down was blocked by OnButton or OnDown, the button-up is already suppressed automatically. Register OnUp on the same button to observe or act on the release without needing to set block: true on the OnUp handler.

    Parameters

    • combo: string

      Button combination string, e.g. "LButton", "Shift+LButton".

    • callback: () => void

      Function invoked on button-up.

    • Optionaloptions: MouseButtonOptions

      Optional configuration. See MouseUpOptions for details.

    Returns void

    // Measure LButton hold duration
    let pressedAt = 0;
    Mouse.OnDown("LButton", () => { pressedAt = Date.now(); });
    Mouse.OnUp("LButton", () => {
    Console.Log("held for " + (Date.now() - pressedAt) + "ms");
    });

    mouse