- kill
- close
- quit
- active
- desktop
- process
- window
- title
- class
- switchto
- switchtowait
- list
- find
- findall
- post
- send
- findimage
The win
library provides essential functions for the Windows platform.
local win = libs.win;
Kills the process with the specified process name or ID.
win.kill(1234);
win.kill("calc.exe");
Sends a close
window message to the specified process name or ID.
win.close(1234);
win.close("calc.exe");
Sends a quit
application message to the specified process name or ID.
win.quit(1234);
win.quit("calc.exe");
Returns the window handle of the active (foreground) window.
hwnd = win.active();
Returns the window handle of the desktop.
hwnd = win.desktop();
Returns the process ID of the process with the specified name.
pid = win.process("calc.exe");
Returns the window handle of the process with the specified name or ID.
hwnd = win.window("calc.exe");
Returns the title of the specified window handle or process name.
title = win.title(1234);
title = win.title("calc.exe");
Returns the class name of the specified window or process.
cls = win.class(1234);
cls = win.class("calc.exe");
Changes the active window to the specified window or process.
win.switchto(1234);
win.switchto("calc.exe");
Changes the active window to the specified window or process and waits until it becomes active.
win.switchtowait(1234);
win.switchtowait("calc.exe");
A timeout can also be specified (default 100 ms).
win.switchtowait(1234, 500);
win.switchtowait("calc.exe", 500);
Returns an array of tasks running on the computer.
tasks = win.list();
Where each task is represented by an object like this:
{ Handle = 1234,
Title = "foobar",
Name = "foobar.exe" }
All processes can be listed by specifying all
as true
.
processes = win.list(true);
Finds the window with the specified class
and/or title
.
hwnd = win.find("ChromeWidgetWin_1", nil);
hwnd = win.find(nil, "Calculator");
hwnd = win.find("foobar_class", "foobar");
Finds the window with the specified class
and/or title
with the given parent
and the preceeding child after
.
parent = win.find("ChromeWidgetWin_1", nil);
hwnd = win.find(parent, 0, "foobar", nil);
Returns a list of windows with the specified class
and/or title
for the given parent
.
-- Find handle to Chrome browser
parent = win.find("ChromeWidgetWin_1", nil);
-- List all children windows (i.e. all of the tabs)
tabs = win.findall(parent, "ChromeWidgetWin_1", nil, true);
Posts a message to the specified window and returns if it succeeded.
hwnd = win.find("ChromeWidgetWin_1", nil);
success = win.post(hwnd, 0x1234, 0, 0);
Sends a message to the specified window and returns the result.
hwnd = win.find("ChromeWidgetWin_1", nil);
result = win.send(hwnd, 0x1234, 0, 0);
Performs image matching with the specified image
file.
x,y = win.findimage("play_button.png");
A specific window handle can be specified, otherwise the entire screen is used.
hwnd = win.find("ChromeWidgetWin_1", nil);
x,y = win.findimage("play_button.png", hwnd);