Win API

This API allows AngelScript scripts to interact with Windows:

  • Find windows by title or class

  • Read window titles, classes, positions, sizes

  • Detect whether a window is foreground or active

  • Read or write clipboard text

  • Discover the thread & process IDs for a window

  • Send messages (WM_CHAR, WM_KEYDOWN, WM_KEYUP, etc.)

  • Send global keyboard/mouse events (SendInput)

Handles (hwnd) are represented as uint64 values.


Window Lookup

uint64 find_window(const string &in title)

Finds a top-level window by its title.

Returns 0 if not found.


uint64 find_window(const string &in title, const string &in className)

Finds a window by title and class name.

Pass empty string ("") to ignore a filter.

Returns 0 if not found.


Window Information

bool get_window_size(uint64 hwnd, int &out w, int &out h)

Retrieves the window’s width and height (outer size).

Returns false if the window is invalid.


bool get_window_rect(uint64 hwnd, int &out x, int &out y, int &out w, int &out h)

Retrieves full window rect:

  • x, y — top-left screen coordinates

  • w, h — size in pixels

Returns false on failure.


bool get_window_title(uint64 hwnd, string &out title)

Gets the window’s title text (UTF-8).

  • Returns true even for empty titles.

  • Returns false only when the hwnd is invalid.


bool get_window_class(uint64 hwnd, string &out cls)

Gets the Win32 window class name.

Returns false if the window is invalid.


Foreground / Activity

bool set_foreground_window(uint64 hwnd)

Attempts to bring the window to foreground.


bool is_foreground_window(uint64 hwnd)

Returns true if the given window is currently foreground.


bool is_window_active(uint64 hwnd)

Checks whether the window:

  • is valid

  • is visible

  • is not minimized

This is a broader “is active” check.


Clipboard

All clipboard strings are UTF-8.

bool copy_to_clipboard(const string &in text)

Copies text into the Windows clipboard.


bool copy_from_clipboard(string &out text)

Reads text from the Windows clipboard.

  • Returns true if any text was successfully retrieved.

  • Empty clipboard → empty string.


Thread & Process Info

bool get_window_thread_process_id(uint64 hwnd, uint &out tid, uint &out pid)

Retrieves:

  • tid — thread ID

  • pid — process ID

Returns false if the hwnd is invalid.


Messaging

bool post_message(uint64 hwnd, uint msg, uint64 wparam, uint64 lparam)

Posts a raw Win32 message to a window.

Examples:

  • post_message(hwnd, 0x0010, 0, 0) → WM_CLOSE

  • post_message(hwnd, 0x0100, VK_A, 0) → WM_KEYDOWN for ‘A’

Returns false if the hwnd is invalid.


Keyboard Input

Global keyboard (SendInput)

These functions simulate real keyboard events globally.

void win_key_down(uint vk)

Simulates a key-down.

void win_key_up(uint vk)

Simulates a key-up.

void win_key_press(uint vk, uint delay_ms = 30)

Press → delay → release.

  • delay_ms clamped to 0..1000.


Window-targeted typing (PostMessage)

bool send_char(uint64 hwnd, const string &in text)

Sends a single character to a window using WM_CHAR.

  • Only the first UTF-16 code unit is used.


bool send_key(uint64 hwnd, uint vk)

Sends:

  • WM_KEYDOWN

  • WM_KEYUP

…to a specific window.


Mouse Input

Mouse input uses real global SendInput events.

void mouse_move(int x, int y)

Moves the mouse to absolute screen coordinates.

void mouse_move_relative(int dx, int dy)

Moves the mouse relative to the current cursor position.


void mouse_left_click()

Left button click.

void mouse_right_click()

Right button click.

void mouse_middle_click()

Middle button click.

Each sends DOWN → small wait → UP.


void mouse_scroll(int amount)

Scroll amount in “wheel notches”:

  • positive → scroll up

  • negative → scroll down


void send_mouse_input(int64 dx, int64 dy, uint flags, uint mouse_data)

Send input manually via raw input.


Util

int64 get_tickcount64()

  • GetTickCount64()


Examples

Find a window & print info


Clipboard


Global keyboard


Send chars to a window


Mouse interaction

Full API Test

Last updated