MacroMonkey.com - Home

Automation - Macro - Bot - Scripting system.



User Input:

Simulated and utility user inputs library.


Keyboard:

If optional HWND (window handle) is included in the argument then input is sent directly to the targets message queue.

This is the preferred way as it possibly allows the application to be minimized and receive input at the same time.

If there is no HWND argument, MM will use the SendInput() API that sends global key presses directly on the desktop.

If the input is intended to a specific target window and needs to be in focus then it can be forced via

win.SetState(hHwnd, indow.SW_SHOW)”.



input.KeySetDelay(delay)     Sets the internal key down delay in milliseconds.. Depending on how the target processes the keys, such as if it polls it’s inputs, then this delay might need to be tweaked. Also effects how fast keys are typed out with the KeyString() function.

Default is 20ms; valid range is 0 to 2000ms.

delay = input.KeyGetDelay()    Get current key down delay (milliseconds).


input.KeyPress(key, [ HWND])     Momentary key press by virtual key code.

input.KeyPressRaw(key, [ HWND])    Momentary key press by raw key code number without translation.

input.KeyHold(key, [ HWND])     Hold key down by virtual key code (until released by KeyRelease()).

input.KeyRelease(key, [ HWND])    Release key by virtual key code.

input.KeyString(szText, [ HWND])    Output a string as if it were typed by hand.


state = input.KeyGetState(keycode)     Get key state by virtual key code. 0 means key up, 1 key is down, 2 key was

down since last call. The 2 case is somewhat unpredictable, so it’s

generally better to look at the return as being 0 or 1.


Special virtual key code constants:

    input.VK_LSHIFT, input.VK_RSHIFT, input.VK_LCONTROL

    input.VK_RCONTROL, input.VK_LMENU, input.VK_RMENU



Virtual key code constants:

‘A’ to ‘Z’, and ‘a’ to ‘z’

input.VK_BACK

input.VK_TAB

input.VK_RETURN

input.VK_SHIFT

input.VK_CONTROL

input.VK_MENU - aka "ALT" key

input.VK_PAUSE

input.VK_CAPITAL - aka "Caps Lock"
input.VK_ESCAPE

input.VK_SPACE

input.VK_PRIOR

input.VK_NEXT

input.VK_END

input.VK_HOME

input.VK_LEFT

input.VK_UP

input.VK_RIGHT

input.VK_DOWN

input.VK_SNAPSHOT – aka “Prt Scrn”

input.VK_INSERT

input.VK_DELETE

input.VK_HELP

input.VK_LWIN

input.VK_RWIN

input.VK_APPS

input.VK_NUMPAD0

input.VK_NUMPAD1

input.VK_NUMPAD2

input.VK_NUMPAD3

input.VK_NUMPAD4

input.VK_NUMPAD5

input.VK_NUMPAD6

input.VK_NUMPAD7

input.VK_NUMPAD8

input.VK_NUMPAD9

input.VK_MULTIPLY - Num pad

input.VK_ADD - Num pad

input.VK_SUBTRACT - Num pad

input.VK_DECIMAL - Num pad

input.VK_DIVIDE - Num pad “Del”

input.VK_F1

input.VK_F2

input.VK_F3

input.VK_F4

input.VK_F5

input.VK_F6

input.VK_F7

input.VK_F8

input.VK_F9

input.VK_F10

input.VK_F11

input.VK_F12

input.VK_NUMLOCK

input.VK_SCROLL



Mouse:

Like keyboard, If optional HWND (window handle) is included in the argument then input is sent directly to the targets

message queue, else it is sent to the desktop in a global fashion.


x, y = input.MouseGetPos()    Get current mouse position in desktop coordinates.


Example:

x, y = input.MouseGetPos()

print(x, y)


input.MouseSetPos(x, y)    Set the absolute mouse cursor position in desktop coordinates.

input.MouseClick(button, [HWND], [x, y])    Click a mouse button. 0 Left, 1 Middle, 2 Right . If optional HWND is

supplied the mouse click is sent as a message to the window. Also optional

coordinates for this message type.



input.MouseHold(button, [HWND], [x, y])     Hold a button down (typically left button) to do “drag”, etc.

input.MouseRelease(button, [HWND] [x, y])     Release a button (typically left button) to do “drop”, etc.


Button constants:

    input.MOUSE_LEFT, input.MOUSE_MIDDLE, input.MOUSE_RIGHT


input.MouseSetDelay(time)    Set mouse click time in milliseconds. Depending on how the target processes the mouse clicks this delay might need to be adjusted for consistent operation.

Default is 20ms; valid range is 0 to 2000ms.

delay = input.MouseGetDelay()     Get mouse click time (milliseconds).


Examples:

-- Move mouse cursor to 100,100 and drag and drop to 200,200

input.MouseSetPos(100, 100)

input.MouseHold(input.MOUSE_LEFT)

time.Sleep(.250)

input.MouseSetPos(200, 200)

time.Sleep(.250)

input.MouseRelease(input.MOUSE_LEFT)


-- Use HWND message type to directly send mouse click to a window/control.

input.MouseClick(button, hWnd, 1,1)