This API exposes a small subset of the Win32 window, clipboard, keyboard, mouse and messaging functions to Lua:
Work with windows via handles (hwnd as integer).
Inspect window rectangles and sizes.
Check if a window is foreground or “active”.
Read / write text to the clipboard (UTF-8).
Look up the thread & process IDs for a window.
Send messages, keys, and characters to a window.
Send global keyboard and mouse input via SendInput.
Window Lookup & Info
find_window(title [, class]) -> hwnd | nil
Search for a top-level window.
title — window title to match (UTF-8 string).
class — optional window class name (UTF-8 string).
If both are provided, both must match.
Returns hwnd (integer) or nil if not found.
get_window_size(hwnd) -> width, height | nil, nil
Get the window’s outer size in pixels.
hwnd — window handle (integer).
Returns:
width, height (integers), or
nil, nil if the handle is invalid or the call fails.
get_window_rect(hwnd) -> x, y, width, height | nil, nil, nil, nil
Get the window’s full rectangle in screen coordinates.
x, y — top-left screen coordinates.
width, height — size in pixels.
Returns all nil on failure.
Window Focus & Activity
is_foreground_window(hwnd) -> bool
Checks if hwnd is the current foreground window.
is_window_active(hwnd) -> bool
Checks if a window is “active” in a broad sense:
Returns true or false.
Window Text & Class
get_window_title(hwnd) -> string | nil
Get the window’s title as a UTF-8 string.
Returns "" for empty titles.
Returns nil if the handle is invalid.
get_window_class(hwnd) -> string | nil
Get the window’s class name.
Returns "" if class name can’t be read.
Returns nil if the handle is invalid.
set_foreground_window(hwnd) -> bool
Attempts to bring the given window to the foreground.
Returns true on success, false otherwise.
All clipboard operations use UTF-8 strings.
copy_to_clipboard(text) -> bool
Copies a Lua string into the system clipboard.
Returns true on success, false on failure.
copy_from_clipboard() -> string
Reads UTF-8 text from the system clipboard.
Returns "" (empty string) if:
clipboard cannot be opened,
the clipboard doesn’t contain text, or
Thread / Process Info
get_window_thread_process_id(hwnd) -> thread_id, process_id | nil, nil
Returns IDs associated with a given window.
thread_id — thread that owns the window.
process_id — process that owns the thread.
If the handle is invalid or the IDs can’t be obtained, returns nil, nil.
Messages & Keys
post_message(hwnd, msg, wparam, lparam) -> bool
Low-level API to post a message to a window.
msg — message ID (e.g., 0x0010 for WM_CLOSE).
wparam, lparam — integer parameters.
Returns true on success.
These functions send global keyboard input (not scoped to a specific window). Use when you simply want to simulate key presses.
Virtual keys are integers (e.g. 0x41 for A, 0x11 for Ctrl, 0x0D for Enter).
win_key_down(vk)
Simulate key down for virtual key vk.
win_key_up(vk)
Simulate key up for virtual key vk.
win_key_press(vk [, delay_ms])
Press and release a key, with an optional delay.
delay_ms — optional delay in milliseconds between down and up (default ~30, clamped to 0..1000).
Message-based character & key sending
These functions target a specific window using messages (WM_CHAR, WM_KEYDOWN, WM_KEYUP).
send_char(hwnd, text) -> bool
Sends a single character via WM_CHAR.
text — Lua string; only the first UTF-16 code unit is used, which is fine for most BMP characters.
Returns true on success.
send_key(hwnd, vk) -> bool
Sends a key to a specific window using WM_KEYDOWN and WM_KEYUP.
Returns true if both messages were posted successfully.
All mouse functions send global input via SendInput.
Coordinates are in screen pixels (primary monitor), unless noted otherwise.
mouse_move(x, y)
Moves the cursor to absolute screen coordinates.
(0,0) is top-left of the primary display.
Coordinates are converted to the normalized range expected by SendInput.
mouse_move_relative(dx, dy)
Moves the cursor relative to its current position.
dx — horizontal delta (pixels).
dy — vertical delta (pixels).
mouse_left_click()
Performs a left button click at the current cursor position.
mouse_right_click()
Performs a right button click.
mouse_middle_click()
Performs a middle button click.
Each click sends a down event, waits ~10 ms, then sends an up event.
Send input manually via raw input.
Scrolls the mouse wheel vertically.
Example: mouse_scroll(3) scrolls up 3 notches.
get_tickcount64()
Find a window and print info
Global keystrokes
Message-based typing into a window
Mouse movement & clicks