Events
All events in MicroMacro will be passed to the macro.event() TODO: Link to function 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. 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 was brought to focus.

#keypressed number vk, boolean toggle

Triggered whenever a key is pressed (not held down). Pushes two additional values: the virtual key (vk) 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 keyboard.getToggleState() and keyboard.pressed() for more information.

#keyreleased number vk, boolean toggle

Triggered whenever a key is released. Pushes two additional values: the virtual key (vk) 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.

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

#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 to standardize functionality.

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 to standardize functionality.

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 pressed (1-32).

#gamepadpovchanged number gamepadId, number pov

Triggered whenever the direction of the POV-hat (aka D-pad) is changed. Returns the gamepad ID (1-16) and new POV direction (0-360 or 655 [centered, not pressed]).

See gamepad.getPOV() and Gamepad global variables 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 (1-16), ID of axis that was changed, and the actual new value of the axis (0-100).

Gamepad joysticks will generally have two axis each: one for horizontal movement, and one for vertical movement.

See gamepad.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 sockaddr sockAddr, string msg

Triggered whenever any socket receives some information.

On a TCP connection, this pushes the socket ID and the content of the message as a string.

On a UDP connection, this pushes the socket sockAddr and the content of the message as a string. You will use the sockAddr to respond to messages.

Example: function macro.event(e, ...) if( e == "socketconnected" ) then -- Only a TCP server socket would receive this kind of event; UDP sockets are connectionless. local socket,listenSockId = ...; -- Pull the socket and listenSockId out of the event clients[socket:id()] = socket; end if( e == "socketreceived" ) then -- TCP local sockId,message = ...; -- Pull the sockId and message out of the event local client = clients[sockId]; -- We remember our client from their socketconnected event client:send("Hello to you, too!"); -- Send a message back over their socket -- UDP local sockAddr,message = ...; -- Pull the sockaddr and message out of the event server:sendto(sockAddr, "Hello to you, too!"); -- Send a message back over the same sockaddr to reply to them end end
#socketerror number socketId, number errorCode

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

#quit

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

Page last updated at 2018-09-25 20:47:27


Copyright 2018