LazHIDControl
LazHIDControl is an open-source desktop automation package for the Lazarus IDE and Free Pascal. A program that uses it can type text, press keys, move and click the mouse, register global hotkeys, find and control other programs' windows, take screenshots, and watch the clipboard, the power supply and session idle time.
The project has three parts: ten nonvisual components for the form designer, the library underneath them, and hidctl, a command-line tool that drives any program from a script.
- Project: LazHIDControl on GitHub
- Developer: Tony Stone
- License: BSD Zero Clause (0BSD)
- Language: Object Pascal
- Dependencies: LCL and FCL. On Linux also the X11, Xtst and D-Bus libraries
- Platforms: Linux, Windows, macOS

Overview
LazHIDControl grew out of MouseAndKeyInput, the package that ships with Lazarus for sending mouse and key input. It covers the same ground and adds window control, global hotkeys, screenshots, system monitoring and a scripting tool.
The same code runs on Linux, Windows and macOS. Coordinates count from the inside of the target window, below its title bar, so a click lands in the same place on every system.
Text is sent as characters, not as key positions, so it comes out right on any keyboard layout. Unicode text is supported.
Components
Installing the package adds ten nonvisual components to the component palette.
| Component | Description |
|---|---|
THIDHotkey |
Registers a global shortcut and fires OnHotkey from any application. |
THIDKeyboard |
Types text, Unicode included, and sends keys with modifiers to the focused application. |
THIDMouse |
Moves, clicks and scrolls. Coordinates can be relative to the screen, a control or a window. |
THIDWindow |
Finds windows by title, class or process. Waits for them, activates, moves and resizes them. |
THIDScreenshot |
Captures the desktop, a monitor, a window, a rectangle or a drag selection. |
THIDClipboardMonitor |
Fires OnChanged when the clipboard content changes, without reading it. |
THIDPowerMonitor |
Sleep and wake notifications, power source, battery percentage and charging state. |
THIDSystemIdle |
Fires OnIdle and OnActive as session input stops and resumes. |
THIDInputMonitor |
Reports key presses and mouse clicks anywhere on the system, for recording a task to play back. |
THIDPermission |
Explains which permissions the desktop needs and requests them. |
Every component reports errors through OnError rather than dialogs, and does nothing in the designer or at form load beyond what was enabled.
Using the components
// A THIDWindow and a THIDMouse on a form, WindowTitle set in the Object Inspector
if Window.Find then
begin
Window.Activate;
Mouse.RelativeWindow := Window;
Mouse.MoveTo(200, 150); // 200,150 inside that window, wherever it is
Mouse.Click;
end;Using the library directly
The components are optional. The library can be called on its own:
uses HIDMouseAndKeyInput, LCLType;
KeyInput.PressString('Hello World!');
KeyInput.Press(VK_RETURN);
MouseInput.Move([], 100, 100, 500); // move there over 500 ms
MouseInput.Click(mbLeft, []);A text expander
A THIDHotkey with ShortCut set to Ctrl+Alt+D and a THIDKeyboard beside it make a small text expander. The date is typed into whatever program has the focus:
procedure TForm1.HIDHotkey1Hotkey(Sender: TObject);
begin
HIDKeyboard1.TypeText(FormatDateTime('yyyy-mm-dd', Date));
end;hidctl
hidctl is a command-line tool built on the same library. It accepts the command names of xdotool, chained on one line:
hidctl search --name "Text Editor" windowactivate key ctrl+a type "Hello" key ReturnIt also runs scripts, one command on each line, with coordinates relative to the target window. A script keeps working when the window opens somewhere else on the screen:
./hidctl/hidctl --window "Some App" - <<EOF
waitfor 5000 Some App
at 300 200
click
type Hello from a script
shot /tmp/proof.png
EOFhidctl covers the pointer, the keyboard, finding and placing windows, screenshots, the clipboard, idle time and power status.
One script on every desktop
The same hidctl script file drives the same program on Linux, Windows and macOS and gets the same result. The project's own test types Unicode text, selects with Shift, ticks a box, clicks a button, picks a list item with the arrow keys, presses a key combination, clicks, right-clicks, double-clicks, drags and scrolls. The program under test writes down what reached it, and that is compared line for line.
The test window after the script has run, one run on each system:
| Linux, GTK3 | Windows 10 | macOS 15 |
|---|---|---|
![]() |
![]() |
![]() |
This makes hidctl useful for documentation as well as testing. One script can walk a program through its screens and save a screenshot at each step, on each system.
Things that do not carry from one system to another, and that a portable script avoids:
- Shortcuts that differ by system, such as Ctrl+A in a Mac text field.
- Things placed by their size. List rows and menu items have different heights on each widget set, so they are better chosen with the arrow keys.
- Wayland, where no program is told where windows are. Keys and screen coordinates work there, window-relative commands do not.
Installation
- Download or clone the LazHIDControl repository.
- Open Lazarus.
- Select Package → Open Package File (.lpk).
- Open
lazhidcontrol/lazhidcontrol.lpk. - Compile the package.
- Select Use → Install to put the components on the palette.
For library-only use, Use → Add to Project is enough.
From a shell:
lazbuild --add-package-link lazhidcontrol/lazhidcontrol.lpk
lazbuild examples/automation/AutomationDemo.lpi
lazbuild hidctl/hidctl.lpiSupported platforms
The project documentation reports testing on:
| Platform | Environment |
|---|---|
| Linux, X11 | Linux Mint with GTK2 and GTK3. Qt5 on Ubuntu 26.04 |
| Windows | Windows 10 |
| macOS | macOS 15 on Intel, Lazarus 4.8, FPC 3.2.4 |
| Linux, Wayland | KDE Plasma 6 on Ubuntu 26.04, GTK3 |
Typing, keys with modifiers, the mouse, screenshots, clipboard monitoring, idle time and power status are reported working on all four. Global hotkeys and window control work on X11, Windows and macOS.
Wayland
Wayland does not tell a program where windows are, so other programs' windows cannot be found or moved there, and the mouse works in screen coordinates only. Global hotkeys are not available. Typing, the mouse and screenshots go through the desktop's portals, which ask the user once.
macOS

macOS asks the user before a program may control other programs, under System Settings → Privacy & Security: Accessibility for typing, the mouse and moving windows, Input Monitoring for watching keys, and Screen Recording for screenshots of other programs' windows. THIDPermission explains and requests these.
Windows
A program cannot send input to one running as administrator unless it runs as administrator too.
History
LazHIDControl began from LazMouseAndKeyInput, the package Tom Gregorovic wrote in 2008 that ships with Lazarus in components/mouseandkeyinput, with its Cocoa units by Sammarco Francesco. Global hotkeys adapted from the Codebot library by Anthony Walter were added to it. See MouseAndKeyInput for that package.
In October 2026 the keyboard, mouse and hotkey units were written new, so the package could be released under the 0BSD license. Releases before October 2026 were GPL-2.0-or-later, and copies of those stay under it.
Documentation
- README — overview, the components, what is tested on each system.
- Manual — each component in detail, the library beneath them, and notes for each platform.
- hidctl — the command-line tool and the xdotool commands it supports.
- Issue tracker — bug reports and feature requests.
License
LazHIDControl is released under the BSD Zero Clause License (0BSD).
See also
- MouseAndKeyInput — the package it began from, which ships with Lazarus
- LazInk
- Lazarus Packages
- Projects using Lazarus - Components and Libraries
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.


