Events

From SolarStrike wiki
Revision as of 10:28, 21 June 2016 by Elverion (talk | contribs)
Jump to: navigation, search

All events in MicroMacro will be passed to the macro.event() function specified by the script. The first argument given will be a string that identifies the type of event that was triggered. Any additional arguments depends on the type of event being handled.

For example:

function macro.event(e, data1, data2)
	if( e == "keypressed" ) then
		if( data1 == key.VK_SPACE ) then
			print("Space bar was pressed.");
		end
	end
end


focuschanged

number hwnd

Triggered whenever the active, focused window is changed (such as bringing a new window to the foreground). Pushes one additional number: the handle to the window that is being changed to top.


keypressed

number vk, boolean toggle

Triggered whenever a key is pressed (not held down). Pushes two additional values: the virtual key being pushed and its toggle state.

The toggle state refers to the state that the key is changing to. Ie. the capslock key will become activated when this returns true.

See getToggleState() and pressed() for more information.


keyreleased

number vk, boolean toggle

Triggered whenever a key is released. Pushes two additional values: the virtual key being released and its toggle state.

The toggle state refers to the state that the key has just changed to. Ie. the capslock key is activated when this returns false.


mousepressed

number vk, boolean toggle

Triggered whenever a mouse button is pressed. Even though mouse buttons do not typically have a toggle function, a second parameter is returned.

See keypressed event for more information.


mousereleased

number vk, boolean toggle

Triggered whenever a mouse button is released. Even though mouse buttons do not typically have a toggle function, a second parameter is returned.

See keyreleased event for more information.


gamepadpressed

number gamepadId, number buttonId

Triggered whenever a button is pressed on any gamepad. Returns two values: the ID of the gamepad (1-16), and the ID of the button being pressed (1-32).


gamepadreleased

number gamepadId, number buttonId

Triggered whenever a button is released on any gamepad. Returns two values: the ID of the gamepad (1-16), and the ID of the button being released (1-32).


gamepadpovchanged

number gamepadId, number pov

Triggered whenever the direction of the POV-hat (aka D-pad) is changed. Returns gamepad ID and new POV direction.

See getPOV() for more information.


gamepadaxischanged

number gamepadId, number axisId, number axisValue

Triggered whenever an axis of a gamepad is changed. Pushes 3 values: ID of gamepad, ID of axis that was changed, and the actual new value of the axis.

See getAxis() for more information.


error

string msg

Triggered when an error occurs. Not all errors can be recovered from enough to push an error message. Pushes 1 value: a string that describes the error that has occurred.


warning

string msg

Exactly like the error event, except for non-critical errors or other warnings.


consoleresized

Triggered when the MicroMacro console window is resized. Does not push any additional information.


socketconnected

socket clientsock, number listenSockId

Triggered whenever a new connection is received on a listening socket. Pushes a new socket object that you may use to communicate with this new client, and the socket ID of the listening socket that this client connected to.


socketdisconnected

number socketId

Triggered whenever a connection is closed for any reason. The socket ID is pushed; not the socket object.


socketreceived

number socketId, string msg

Triggered whenever any socket receives some information. Pushes the socket ID and the content of the message as a string.


socketerror

number socketId, number errorCode

Triggered whenever an error is encountered on a socket. Pushes the socket ID and the Winsock error code [1].


quit

Triggered when the script is just about to terminate. Does not push any additional information.