Difference between revisions of "Lua API:Event"

From The Powder Toy
Jump to: navigation, search
(Initial documentation for event api)
(No difference)

Revision as of 04:03, 14 February 2019

The Elements API contains methods and constants for listening to events. This is the api you should use if you want to handle mouse and keyboard input. Shorthand: you can use evt. instead of event.

Methods

event.register

function event.register(number eventType, function eventHandler)

Registers an event handler for a certain type of event. See the list of constants at the bottom of the page for possible events you can listen to. Returns eventHandler, in case it's a lambda function and you want to unregister it later.

event.unregister

event.unregister(number eventType, function eventHandler)

Unregister a previously registered event handler. Has no effect of this function wasn't registered or wasn't registered under this event type.

event.getmodifiers

number event.getmodifiers()

Gets the current keyboard modifier state. Includes bits describing whether shift, ctrl, alt, caps lock, num lock, and other modifiers are pressed / set.

Event Types

keypress
keyrelease
textinput
mousedown
mouseup
mousemove
mousewheel
tick
blur
close