1. Attributes

Italics means private (in the sense that they shouldn't be set manually).

Attribute Description
keyboard keyboard event table
keyboard.pressed keyboard pressed events
keyboard.released keyboard release events
mouse mouse event table
mouse.motion mouse motion event
mouse.pressed mouse pressed events
mouse.released mouse released events
joystick joystick event table
joystick.axis_motion joystick axis motion events
joystick.ball_motion joystick ball motion events
joystick.hat_motion joystick hat motion events
joystick.pressed joystick button pressed events
joystick.released joystick button released events
quit quit event
type state variable
state state variable
arg1 state variable
arg2 state variable
arg3 state variable
arg4 state variable

2. Methods

Method Description
new(o) constructor
gather_events() processes all pending events

3. Event Function Prototypes

Event Prototype
mouse.motion function(x, y, xrel, yrel)
mouse.pressed function(x, y)
mouse.released function(x, y)
joystick.axis_motion function(axis, axis_value)
joystick.ball_motion function(ball, xrel, yrel)
joystick.hat_motion function(hat, hat_value)
joystick.pressed function(button)
joystick.released function(button)
quit function()

4. Notes

Joysticks and joystick buttons start numbering at 1, not 0.

5. Usage

--create a new EventManager
evman = EventManager:new()

--add an event to exit when ESC is pressed
-- assumes main loop is controlled by variable "done"
evman.keyboard.pressed[Keys.ESCAPE] = function() done = true end

--events to control a player object's movement
evman.keyboard.pressed[Keys.UP] = function() player.y_vel = -1 end
evman.keyboard.pressed[Keys.DOWN] = function() player.y_vel = 1 end
evman.keyboard.pressed[Keys.LEFT] = function() player.x_vel = -1 end
evman.keyboard.pressed[Keys.RIGHT] = function() player.x_vel = 1 end

evman.keyboard.released[Keys.UP] = function() player.y_vel = 0 end
evman.keyboard.released[Keys.DOWN] = function() player.y_vel = 0 end
evman.keyboard.released[Keys.LEFT] = function() player.x_vel = 0 end
evman.keyboard.released[Keys.RIGHT] = function() player.x_vel = 0 end

--EventManager for a fictional menu object
menu_evman = EventManager:new()
menu_evman.keyboard.pressed[Keys.UP] = function() menu.next_item() end
menu_evman.keyboard.pressed[Keys.DOWN] = function() menu.prev_item() end
menu_evman.keyboard.pressed[Keys.RETURN] = function() menu.execute() end

--Controlling a player with the mouse
-- assume there exists a player:set_pos(x,y) method

--wrapper function for player:set_pos(x,y)
function move_player(x,y)
  player:set_pos(x,y)
end

evman.mouse.motion = move_player(x,y)
evman.mouse.pressed[MouseButton.BUTTON_LEFT] = function() player.firing = true end
evman.mouse.released[MouseButton.BUTTON_LEFT] = function() player.firing = false end

--quitting (assumes main loop is controlled by done variable)
evman.quit = function() done = true end