Difference between revisions of "Lua:getWindowlist"
Jump to navigation
Jump to search
m (Added CodeBox Template.) |
(Major overhaul of the post.) |
||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | {{CodeBox|'''function''' getWindowlist()}} | + | {{CodeBox|'''function''' getWindowlist() ''':''' table}} |
| − | Returns a table | + | Returns a table containing the currently visible window list. |
| − | + | The returned table is grouped by process ID. Each process ID maps to another table where the keys are window IDs and the values are window captions. | |
| − | + | ||
| − | + | ===Function Parameters=== | |
| − | + | This function has no parameters. | |
| − | + | ||
| − | [21112] = { | + | ===Returns=== |
| − | + | Table — A table containing process IDs, window IDs, and window captions. | |
| − | + | ||
| − | + | ===Return Table Structure=== | |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| − | + | !align="left"|Level | |
| − | + | !align="left"|Type | |
| − | } | + | !style="width: 80%;background-color:white;" align="left"|Description |
| + | |- | ||
| + | |PID | ||
| + | |Integer | ||
| + | |The process ID that owns one or more windows. | ||
| + | |- | ||
| + | |Window ID | ||
| + | |Integer | ||
| + | |The index or ID of a window entry belonging to that process. | ||
| + | |- | ||
| + | |Caption | ||
| + | |String | ||
| + | |The caption text of the window. | ||
| + | |} | ||
| + | |||
| + | ===Description=== | ||
| + | getWindowlist returns information about open windows grouped by their owning process ID. | ||
| + | |||
| + | The general structure is: | ||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | windowList[processID][windowID] = windowCaption | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | A single process can have multiple window entries. Some entries may have the same caption, and some windows may have system-generated captions such as IME or framework-related window names. | ||
| + | |||
| + | ===Examples=== | ||
| + | |||
| + | ====Get the window list==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local windowList = getWindowlist() | ||
| + | |||
| + | print(windowList) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Print all window captions==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local windowList = getWindowlist() | ||
| + | |||
| + | for pid, windows in pairs(windowList) do | ||
| + | for id, caption in pairs(windows) do | ||
| + | print("PID: " .. tostring(pid) .. ", ID: " .. tostring(id) .. ", Caption: " .. caption) | ||
| + | end | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Find windows by caption text==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local windowList = getWindowlist() | ||
| + | local searchText = "Cheat Engine" | ||
| + | |||
| + | for pid, windows in pairs(windowList) do | ||
| + | for id, caption in pairs(windows) do | ||
| + | if caption:find(searchText, 1, true) ~= nil then | ||
| + | print("Found: PID=" .. tostring(pid) .. ", ID=" .. tostring(id) .. ", Caption=" .. caption) | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Collect all windows for a specific process ID==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local windowList = getWindowlist() | ||
| + | local targetPID = getOpenedProcessID() | ||
| + | local windows = windowList[targetPID] | ||
| + | |||
| + | if windows ~= nil then | ||
| + | for id, caption in pairs(windows) do | ||
| + | print("Window " .. tostring(id) .. ": " .. caption) | ||
| + | end | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Example return data==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local windowList = getWindowlist() | ||
| + | |||
| + | -- Example shape: | ||
| + | -- windowList = { | ||
| + | -- [21112] = { | ||
| + | -- [1] = "Cheat Engine 7.4", | ||
| + | -- [2] = "Cheat Engine 7.4", | ||
| + | -- [3] = "Cheat Engine settings", | ||
| + | -- [4] = "Default IME", | ||
| + | -- [5] = "Lua Engine", | ||
| + | -- [6] = "MSCTFIME UI" | ||
| + | -- } | ||
| + | -- } | ||
| + | </syntaxhighlight> | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | + | {{Process}} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 19:14, 25 June 2026
Returns a table containing the currently visible window list.
The returned table is grouped by process ID. Each process ID maps to another table where the keys are window IDs and the values are window captions.
Contents
Function Parameters[edit]
This function has no parameters.
Returns[edit]
Table — A table containing process IDs, window IDs, and window captions.
Return Table Structure[edit]
| Level | Type | Description |
|---|---|---|
| PID | Integer | The process ID that owns one or more windows. |
| Window ID | Integer | The index or ID of a window entry belonging to that process. |
| Caption | String | The caption text of the window. |
Description[edit]
getWindowlist returns information about open windows grouped by their owning process ID.
The general structure is:
windowList[processID][windowID] = windowCaption
A single process can have multiple window entries. Some entries may have the same caption, and some windows may have system-generated captions such as IME or framework-related window names.
Examples[edit]
Get the window list[edit]
1 local windowList = getWindowlist()
2
3 print(windowList)
Print all window captions[edit]
1 local windowList = getWindowlist()
2
3 for pid, windows in pairs(windowList) do
4 for id, caption in pairs(windows) do
5 print("PID: " .. tostring(pid) .. ", ID: " .. tostring(id) .. ", Caption: " .. caption)
6 end
7 end
Find windows by caption text[edit]
1 local windowList = getWindowlist()
2 local searchText = "Cheat Engine"
3
4 for pid, windows in pairs(windowList) do
5 for id, caption in pairs(windows) do
6 if caption:find(searchText, 1, true) ~= nil then
7 print("Found: PID=" .. tostring(pid) .. ", ID=" .. tostring(id) .. ", Caption=" .. caption)
8 end
9 end
10 end
Collect all windows for a specific process ID[edit]
1 local windowList = getWindowlist()
2 local targetPID = getOpenedProcessID()
3 local windows = windowList[targetPID]
4
5 if windows ~= nil then
6 for id, caption in pairs(windows) do
7 print("Window " .. tostring(id) .. ": " .. caption)
8 end
9 end
Example return data[edit]
1 local windowList = getWindowlist()
2
3 -- Example shape:
4 -- windowList = {
5 -- [21112] = {
6 -- [1] = "Cheat Engine 7.4",
7 -- [2] = "Cheat Engine 7.4",
8 -- [3] = "Cheat Engine settings",
9 -- [4] = "Default IME",
10 -- [5] = "Lua Engine",
11 -- [6] = "MSCTFIME UI"
12 -- }
13 -- }