Window Module

From SolarStrike wiki
Revision as of 19:54, 7 December 2017 by Elverion (talk | contribs) (pixelSearch)
Jump to: navigation, search

find

number window.find(string windowName[, string className])

Finds a window's HWND based on its title (not case-sensitive), and (optionally) its classname (case-sensitive). 'title' and 'classname' can contain wildcards * and ?.

Returns the first match found. If no match was found, returns nil.


findList

table window.findList(string windowName[, string className])

Finds a list of windows based on title (not case-sensitive), and (optionally) classname (case-sensitive). 'title' and 'classname' can contain wildcards * and ?.

Returns a table of tables containing: 'hwnd' (number; handle to window), 'name' (string; window title), and 'class' (string; identifier used by its programmer). If no match was found, returns nil.

For example, the return value might look like this:

{
	{hwnd = 1234, name = "Window Name 1", class = "Window Class 1"},
	{hwnd = 5678, name = "Window Name 2", class = "Window Class 2"},
	{hwnd = 9012, name = "Window Name 3", class = "Window Class 3"},
}

getParent

number window.getParent(number hwnd)

Returns a window's parent, or nil on error.


getTitle

string window.getTitle(number hwnd)

Returns a window's title as a string.


setTitle

window.setTitle(number hwnd, string title)

Change a window's title.

getClassName

string window.getClassName(number hwnd)

Returns a window's class name as a string.

valid

boolean window.valid(number hwnd)

Returns true if 'hwnd' is a valid window handle, or false otherwise.


getRect

number x, number y, number w, number h window.getRect(number hwnd)

Returns the position (x,y) and size (w,h) of a window.


setRect

window.setRect(number hwnd, number x, number y, number w, number h)

Change the position and size of a window with handle 'hwnd'.


getClientRect

number x, number y, number w, number h window.getClientRect(number hwnd)

Returns the position and size of a window's client area.


setClientRect

window.setClientRect(number hwnd, number x, number y, number w, number h)

Change the position and size of a window's client area with handle 'hwnd'.


show

window.show(number hwnd, number cmd)

Show/hide/minimize/maximize/whatever with the window.

For 'cmd', you should specify one of the following constants:

SW_FORCEMINIMIZE

SW_HIDE

SW_MAXIMIZE

SW_MINIMIZE

SW_RESTORE

SW_SHOW

SW_SHOWDEFAULT

SW_SHOWMAXIMIZED

SW_SHOWMINIMIZED

SW_SHOWMINNOACTIVATE

SW_SHOWNA

SW_SHOWNOACTIVATE

SW_SHOWNORMAL


flash

window.flash(number hwnd, number flashCount)

"Flash" the window to attempt to grab the user's attention. If 'flashCount' is < 0, stop flashing If 'flashCount' is 0, flash until user focuses the window If 'flashCount' is > 0, flash this many times


getPixel

number r, number g, number b window.getPixel(number hwnd, number x, number y)

Get the color of a pixel at (x,y) inside window 'hwnd', and return the color split into red, green, and blue channels. r, g, and b results will be between 0 and 255.


pixelSearch

number x, number y window.pixelSearch(number hwnd, number r, number g, number b, number x1, number y1, number x2, number y2[, number accuracy[, number step]])

Search the given window for a pixel that matches r,g,b within the rectangle outlined by (x1,y1) -> (x2,y2) The rect may go from left-to-right, right-to-left, top-to-bottom, bottom-to-top, or any combination of those, depending on the orientation of the two points.

'accuracy' is how many units each channel must be within the given color to generate a match. ie. with an accuracy of 20, the red, green, and blue channels must be within 20 of the target color to match. Default: 1

'step' is the step size (distance between pixels to search). You generally have no need for this so long as you aren't scanning a large area, but you may experience faster scan times (with a chance of missing a match) with a higher step size. Default: 1

If the pixel is not found, this function returns nil.

saveScreenshot

window.saveScreenshot(number hwnd, string filename)

Save a screenshot of window 'hwnd' to 'filename'. If 'hwnd' is 0, this screenshots the whole desktop. NOTE: You cannot take a screenshot of a minimized window. This is a limitation in Windows.


getAppHwnd

number window.getAppHwnd()

Returns the calling process' (MicroMacro) handle to window (HWND). This is what you may use to access or modify the console's properties where an hwnd is required.


getFocusHwnd

number window.getFocusHwnd()

Returns the hwnd of whichever window is top-most as of the the start of this logic cycle. This is polled once per frame and should be fairly accurate so long as your script executes each logic cycle quickly. Be aware that as windows are being minimized, maximized, or otherwise, the focused hwnd may temporarily switch to NULL (0).