When to use this skill
Manages events, like keypresses. Use this skill when working with event management, event callbacks, event pumping, or any event-related operations in LÖVE games.
Common use cases
- Managing game events and callbacks
- Implementing custom event handling systems
- Working with event queues and pumping
- Handling system and user-generated events
- Managing event flow and propagation
Functions
love.event.clear(): Clears the event queue.
love.event.poll() -> i: function: Returns an iterator for messages in the event queue.
love.event.pump(): Pump events into the event queue. This is a low-level function, and is usually not called by the user, but by love.run. Note that this does need to be called for any OS to think you're still running, and if you want to handle OS-generated events at all (think callbacks).
love.event.push(n: Event, a: Variant, b: Variant, c: Variant, d: Variant, e: Variant, f: Variant, ...: Variant): Adds an event to the event queue. From 0.10.0 onwards, you may pass an arbitrary amount of arguments with this function, though the default callbacks don't ever use more than six.
love.event.quit - Adds the quit event to the queue. The quit event is a signal for the event handler to close LÖVE. It's possible to abort the exit process with the love.quit callback.
love.event.quit(exitstatus: number): No description
love.event.quit('restart': string): Restarts the game without relaunching the executable. This cleanly shuts down the main Lua state instance and creates a brand new one.
love.event.wait() -> n: Event, a: Variant, b: Variant, c: Variant, d: Variant, e: Variant, f: Variant, ...: Variant: Like love.event.poll(), but blocks until there is an event in the queue.
Enums
Event: Arguments to love.event.push() and the like. Since 0.8.0, event names are no longer abbreviated.
focus: Window focus gained or lost
joystickpressed: Joystick pressed
joystickreleased: Joystick released
keypressed: Key pressed
keyreleased: Key released
mousepressed: Mouse pressed
mousereleased: Mouse released
quit: Quit
resize: Window size changed by the user
visible: Window is minimized or un-minimized by the user
mousefocus: Window mouse focus gained or lost
threaderror: A Lua error has occurred in a thread
joystickadded: Joystick connected
joystickremoved: Joystick disconnected
joystickaxis: Joystick axis motion
joystickhat: Joystick hat pressed
gamepadpressed: Joystick's virtual gamepad button pressed
gamepadreleased: Joystick's virtual gamepad button released
gamepadaxis: Joystick's virtual gamepad axis moved
textinput: User entered text
mousemoved: Mouse position changed
lowmemory: Running out of memory on mobile devices system
textedited: Candidate text for an IME changed
wheelmoved: Mouse wheel moved
touchpressed: Touch screen touched
touchreleased: Touch screen stop touching
touchmoved: Touch press moved inside touch screen
directorydropped: Directory is dragged and dropped onto the window
filedropped: File is dragged and dropped onto the window.
jp: Joystick pressed
jr: Joystick released
kp: Key pressed
kr: Key released
mp: Mouse pressed
mr: Mouse released
q: Quit
f: Window focus gained or lost
Examples
Custom event handling
-- Pump and handle events manually
function love.update(dt)
love.event.pump()
for name, a, b, c, d, e, f in love.event.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a or 0
end
end
-- Handle other events
end
end
Event callback
-- Custom quit handler
function love.quit()
-- Save game state before quitting
saveGameState()
return false -- Allow normal quit process
end
Best practices
- Use love.event.pump() regularly to process events
- Handle quit events gracefully
- Consider performance when polling events frequently
- Test event handling on different platforms
- Be mindful of event queue limits
Platform compatibility
- Desktop (Windows, macOS, Linux): Full event support
- Mobile (iOS, Android): Full support
- Web: Full support
1---2name: love-event3description: Manages events, like keypresses. Use this skill when working with event management, event callbacks, event pumping, or any event-related operations in LÖVE games.4license: MIT5---67## When to use this skill8Manages events, like keypresses. Use this skill when working with event management, event callbacks, event pumping, or any event-related operations in LÖVE games.910## Common use cases11- Managing game events and callbacks12- Implementing custom event handling systems13- Working with event queues and pumping14- Handling system and user-generated events15- Managing event flow and propagation1617## Functions1819- `love.event.clear()`: Clears the event queue.20- `love.event.poll() -> i: function`: Returns an iterator for messages in the event queue.21- `love.event.pump()`: Pump events into the event queue. This is a low-level function, and is usually not called by the user, but by love.run. Note that this does need to be called for any OS to think you're still running, and if you want to handle OS-generated events at all (think callbacks).22- `love.event.push(n: Event, a: Variant, b: Variant, c: Variant, d: Variant, e: Variant, f: Variant, ...: Variant)`: Adds an event to the event queue. From 0.10.0 onwards, you may pass an arbitrary amount of arguments with this function, though the default callbacks don't ever use more than six.23- `love.event.quit` - Adds the quit event to the queue. The quit event is a signal for the event handler to close LÖVE. It's possible to abort the exit process with the love.quit callback.24 - `love.event.quit(exitstatus: number)`: No description25 - `love.event.quit('restart': string)`: Restarts the game without relaunching the executable. This cleanly shuts down the main Lua state instance and creates a brand new one.26- `love.event.wait() -> n: Event, a: Variant, b: Variant, c: Variant, d: Variant, e: Variant, f: Variant, ...: Variant`: Like love.event.poll(), but blocks until there is an event in the queue.2728## Enums2930- `Event`: Arguments to love.event.push() and the like. Since 0.8.0, event names are no longer abbreviated.31 - `focus`: Window focus gained or lost32 - `joystickpressed`: Joystick pressed33 - `joystickreleased`: Joystick released34 - `keypressed`: Key pressed35 - `keyreleased`: Key released36 - `mousepressed`: Mouse pressed37 - `mousereleased`: Mouse released38 - `quit`: Quit39 - `resize`: Window size changed by the user40 - `visible`: Window is minimized or un-minimized by the user41 - `mousefocus`: Window mouse focus gained or lost42 - `threaderror`: A Lua error has occurred in a thread43 - `joystickadded`: Joystick connected44 - `joystickremoved`: Joystick disconnected45 - `joystickaxis`: Joystick axis motion46 - `joystickhat`: Joystick hat pressed47 - `gamepadpressed`: Joystick's virtual gamepad button pressed48 - `gamepadreleased`: Joystick's virtual gamepad button released49 - `gamepadaxis`: Joystick's virtual gamepad axis moved50 - `textinput`: User entered text51 - `mousemoved`: Mouse position changed52 - `lowmemory`: Running out of memory on mobile devices system53 - `textedited`: Candidate text for an IME changed54 - `wheelmoved`: Mouse wheel moved55 - `touchpressed`: Touch screen touched56 - `touchreleased`: Touch screen stop touching57 - `touchmoved`: Touch press moved inside touch screen58 - `directorydropped`: Directory is dragged and dropped onto the window59 - `filedropped`: File is dragged and dropped onto the window.60 - `jp`: Joystick pressed61 - `jr`: Joystick released62 - `kp`: Key pressed63 - `kr`: Key released64 - `mp`: Mouse pressed65 - `mr`: Mouse released66 - `q`: Quit67 - `f`: Window focus gained or lost6869## Examples7071### Custom event handling72```lua73-- Pump and handle events manually74function love.update(dt)75 love.event.pump()7677 for name, a, b, c, d, e, f in love.event.poll() do78 if name == "quit" then79 if not love.quit or not love.quit() then80 return a or 081 end82 end83 -- Handle other events84 end85end86```8788### Event callback89```lua90-- Custom quit handler91function love.quit()92 -- Save game state before quitting93 saveGameState()94 return false -- Allow normal quit process95end96```9798## Best practices99- Use love.event.pump() regularly to process events100- Handle quit events gracefully101- Consider performance when polling events frequently102- Test event handling on different platforms103- Be mindful of event queue limits104105## Platform compatibility106- **Desktop (Windows, macOS, Linux)**: Full event support107- **Mobile (iOS, Android)**: Full support108- **Web**: Full support