Process Functions

From SolarStrike wiki
Revision as of 19:47, 13 July 2008 by Elverion (talk | contribs) (New page: == attach == '''attach(window)''' Attaches MicroMacro's input to another window. You may only attach to a single window at a time. When using attached input, MicroMacro will send input di...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

attach

attach(window)

Attaches MicroMacro's input to another window. You may only attach to a single window at a time. When using attached input, MicroMacro will send input directly to the specified window; meaning it will not interfere with other windows if you switch focus and may allow you to continue sending input while it is in a minimized state. Note that this does not work for all applications, and you may still need to keep the window focused for input to register.

If you are running in an attached state, and have the target window on top, MicroMacro will use a combination of posting messages to the target's input queue, as well as sending simulated keyboard messages. This is done for compatibility.


Example

attach( findWindow("mygame") );

detach

detach()

Removes the attachment to whichever window was specified when using attach(). After detaching, MicroMacro will no longer specifically target it's previously attached window.


Example

attach( findWindow("mygame") );
yrest(100);
detach();

openProcess

handle openProcess(proc)

Opens the process for reading/writing of memory. Returns a handle to the process, or 0 on failure. Accepts a process ID. You should use findProcess() if applicable. You should use closeProcess() to close the process handle when you are done, however, no serious problems will arise if you forget.

You should store the handle in a variable; You will need it for reading and writing memory.


Example - Using process ID

myProcess = openProcess( 1234 );
if( myProcess == 0 ) then
  print("Could not find and open the process");
end

Example - Using window name

myProcess = openProcess( findProcess("The window name") );
if( myProcess == 0 ) then
  print("Could not find and open the process");
end


closeProcess

closeProcess(proc)

Closes the specified handle to the process. You should close any handles that you are no longer using, but it is not necessary. MicroMacro will automatically close any handles that have gone out of scope in your scripts. Closing process handles will help to free system resources when needed, but is unnecessary unless you are opening hundreds of processes in a short amount of time.

Example

myProcess = openProcess( findProcess("The window name") );
closeProcess( myProcess ); -- myprocess is closed. You must re-open it in order to
-- read or write memory from/to it.


findProcess

process findProcess(windowname)

Finds the window's process with the specified window name. Must be exact, but accepts wild cards '*' and '?'. Returns a process ID on success, 0 on failure. This will only return on the first window to match; so you might not find the correct window if multiple windows have the same, or similar, names.


Example - No wild cards

myProcess = openProcess( findProcess("Mozilla Firefox") );

This example will target only windows named exactly "Mozilla Firefox".

Example - Single character wild cards

myProcess = openProcess( findProcess("M?zilla F?refox") );

This example will target windows named "M?zilla F?refox" where _ can be any single character.

Example - Full wild cards

myProcess = openProcess( findProcess("Mozilla *") );

This example will target windows named that start with "Mozilla ", including "Mozilla Firefox" as well as "Mozilla Thunderbird".


findProcessByExe

process findProcessByExe(exeName)

Finds the application's process with the specified name. Accepts wildcards '*' and '?'. Returns a process ID on success, 0 on failure. This will only return on the first process to match; so you might not find the correct process if multiple processes have the same, or similar, names.

See findProcess() for more information on wild cards.

Example

myProcess = openProcess( findProcessById("mygame.exe") );


findProcessByWindow

process findProcessByWindow(window)

Finds the process which belongs to the specified window. Returns a process ID on success, 0 on failure.

See findProcess() for more information on wild cards.

Example

win = findWindow("Untitled - Notepad");
proc = findProcessByWindow(win)


findWindow

window findWindow(windowName)

Finds the window with the specified name. Accepts wildcards '*' and '?'. Returns a handle to the window on success, 0 on failure. This will only return on the first window to match; so you might not find the correct window if multiple windows have the same, or similar, names.


See findProcess() for more information on wild cards.

Example

myWindow = findWindow("Untitled - Notepad");


findWindowList

table findWindowList(windowName)

Finds all windows that match the specified mask. Accepts wildcards '*' and '?'. Returns a full table on success, or an empty table on failure. You may use getWindowName() to find each window's name.


See findProcess() for more information on wild cards.

Example

myList = findWindowList("Untitled - Notepad");
for i = 1,#myList do
  printf("Found window %x [%s]\n", myList[i], getWindowName(myList[i]));
end


foregroundWindow

window foregroundWindow()

Finds the window that is on top. Returns a handle to the window on success, 0 on failure.

Example

myWindow = foregroundWindow();


getHwnd

window getHwnd()

Returns MicroMacro's window. You can use this to set the window title of the calling MicroMacro window.

Example

mmwin = getHwnd();
setWindowName(mmwin, "This is an example");


getPath

string getPath()

Returns the full path to MicroMacro's directory.

Example

path = getPath();


getWindowName

string getWindowName(window)

Returns the window title of the specified window.

Example

win = findWindow("*");
printf("Found window is named: %x\n", getWindowName(win));


setWindowName

setWindowName(window, name)

Changes the specified window's title.

Example win = findWindow("*"); setWindowName(win, "Changed"); </source> After running the above example, the first window found by findWindow() will have it's window title changed to "Changed".


windowRect

x,y,w,h windowRect(window)

Returns the rectangle that contains the window. 4 integers are returned: x, y, width, height (in that order). If the window is minimized, x and y will be -32000 while width and height will be 0. Variables x and y represent the top-left corner of the client region of the window. Variables width and height represent the width and height of the client area within the window. This can be used to find the top left corner of the window to be used as offset values in functions such as mouseSet() to ensure that the coordinates are within the window's boundaries. It may also be used to find which resolution a user is running the target program under.

Example window = findWindow("Untitled - Notepad"); x,y,w,h = windowRect(window);

printf("window is at (%d,%d) and is %d wide, and %d high.", x, y, w, h); </source>


openDC

hdc openDC(window)

Returns the Handle to Device Context (HDC) of the specified window. Some functions may require an HDC to read/draw to and from their screen bitmaps.

Typically, you will want to only open an HDC to a window once and leave it open until it is no longer needed. Do not continuously re-open an HDC to the same window all the time, as this consumes system resources.

Example window = findWindow("Untitled - Notepad"); hdc = openDC(window); </source>


closeDC

closeDC(hdc)

Releases a Handle to Device Context that was retrieved using openDC(). You do not need to use this function, as the HDC will automatically be closed once the variable goes out of scope, however, it is in good practice to do so.

Example window = findWindow("Untitled - Notepad"); hdc = openDC(window); closeDC(hdc); </source>


makeColor

color makeColor(r, g, b)

Returns a color value for the given red, green, blue values. r, g, and b should be an integer between 0 and 255.

Example pink = makeColor(255, 0, 255); </source>


getPixel

r,g,b getPixel(hdc, x, y)

Returns the red, green, and blue values of the pixel located at (x,y) on the HDC (opened by openDC()). This can be used to read color values from the screen. The coordinates, x and y, are window coordinates, not screen coordinates! The returned values (r, g, b) will be integers between 0 (none) and 255 (full).

Note that if the user is running under different color depth, has a vastly different video card, or different video settings, it could cause the color values returned to be different by up to (on average) +- 15 per channel. You should always allow for a wide range per channel if you are checking a specific pixel for information.

Example hdc = openDC( findWindow("Untitled - Notepad") ); r,g,b = getPixel(hdc, 12, 24); printf("RGB: %d, %d, %d", r, g, b); </source>


setPixel

setPixel(hdc, x, y, color)

Draws a pixel onto the HDC at (x,y) with color 'color'. 'color' should be generated through the use of makeColor().

If you will be writing pixels to the screen often (say, in a for loop), then it is not good practice to continuously call makeColor() to generate a color value. If you will be using the same color over and over, generate the color once, store it in a variable, and use the variable instead.

Example hdc = openDC( findWindow("Untitled - Notepad") ); setPixel(hdc, 12, 24, makeColor(255,0,255)); </source>


drawLine

drawLine(hdc, x1, y1, x2, y2, color, size)

Draws a line onto the hdc from (x1,y1) to (x2,y2) with the given color and size. 'color' should be generated using makeColor(), and size should be an integer specifying the width of the line in pixels.

Example window = findWindow("Untitled - Notepad");

hdc = openDC(window); drawLine(hdc, 32,32, 128,64, makeColor(255, 0, 255), 2); </source>


drawRect

drawRect(hdc, x1, y1, x2, y2, color, size)

Draws a rectangle onto the hdc from (x1,y1) to (x2,y2) with the given color and size. 'color' should be generated using makeColor(), and size should be an integer specifying the width of the lines in pixels.

Example window = findWindow("Untitled - Notepad");

hdc = openDC(window); drawRect(hdc, 32,32, 128,64, makeColor(255, 0, 255), 2); </source>