Function ControlClickByHandle

  • Simulates a mouse click on a control. Unlike MouseClick, ControlClickByHandle won't move the mouse cursor but is capable of clicking on controls that may be obscured by other windows.

    Where possible, you should prefer using this function over ControlClick to avoid potential issues with ambiguous window and control titles.

    Parameters

    • windowHandle: bigint

      The handle of the window to access.

    • controlHandle: bigint

      The handle of the control to interact with.

    • button: MouseButton = MouseButton.Left

      The mouse button to click. Default is MouseButton.Left.

    • clicks: number = 1

      The number of times to click the mouse. Default is 1.

    • x: number = AU3_INTDEFAULT

      The x position to click within the control. Default is the center.

    • y: number = AU3_INTDEFAULT

      The y position to click within the control. Default is the center.

    Returns number

    1 if success, 0 if failed.

    import { ControlClickByHandle, ControlGetHandle, MouseButton, WinGetHandle } from '@ahmic/autoit-js';

    const windowHandle = WinGetHandle('Untitled - Notepad');
    const controlHandle = ControlGetHandle(windowHandle, 'Edit1');

    // Click the Notepad window's edit control.
    ControlClickByHandle(windowHandle, controlHandle);

    // Right click the Notepad window's edit control.
    ControlClickByHandle(windowHandle, controlHandle, MouseButton.Right);

    // Double click the Notepad window's edit control.
    ControlClickByHandle(windowHandle, controlHandle, MouseButton.Left, 2);