Application

Mouse, Keyboard, and Input

LeftClick, LeftDoubleClick, and RightClick operate on the element matched by the current selector. Hover moves the mouse over the element. MoveTo moves the cursor to the element position. Focus sets keyboard focus to the matched element. SendString types a literal string. SendKey sends virtual key codes for Enter, Tab, arrow keys, and other special keys. PressModifierKey and ReleaseModifierKey hold modifier keys across subsequent actions. SwitchToTab switches focus to a TabControl element matched by the current selector. SendKeyCode sends one virtual key code to the element, for a key that has no character to type.

NOTE

A left click is not one thing. On a control that can be selected, a list item, a tree item, a data item or a tab item, a left click selects it through SelectionItemPattern. On anything else that offers InvokePattern, a button or a menu item, it invokes the control's default action. A double click invokes that default action too, because activating is what a double click means to an item. A click holding a modifier always goes to the mouse, and so do middle and right clicks, because no pattern expresses either. A control offering no pattern for the click being asked for is clicked with the mouse, and that is the primary route for it rather than a fallback from one. WithSimulateMouse on a selector asks for the mouse regardless, which is what to reach for when a control's default action is not what a click should do to it.

Examples

GPAL Fluent: High-level fluent C# API

//SendKey accepts Windows virtual key codes as a byte. Common values: 0x0D = Enter, 0x09 = Tab, 0x1B = Escape, 0x26/0x28 = Up/Down Arrow. Use SendString for printable characters.

// Click a button and type in a text field

GPAL.Application

.Open("C:\MyApp\app.exe")

.WithSelector(GPAL.Selector.WithAutomationID("txtSearch").ToGPALObject())

.LeftClick()

.SendString("search term")

.SendKey(0x0D) // Enter

.WithSelector(GPAL.Selector.WithAutomationID("btnExport").ToGPALObject())

.LeftClick();


// Use modifier keys

GPAL.Application

.Open("C:\MyApp\app.exe")

.WithSelector(GPAL.Selector.WithAutomationID("txtNotes").ToGPALObject())

.PressModifierKey(ModifierKeys.Control)

.SendKey(0x41) // Ctrl+A

.ReleaseModifierKey(ModifierKeys.Control)

.SendString("replacement");

💬 Ask GPAL