Questions about Runtime:addEventListener

Hello, I’m kinda new to solar2d and just trying to build something simple to learn.
I was trying to create an event that triggers everytime the user left-clicks (i.e primarymousebutton)
Searching for answers I tried:
Runtime:addEventListener( “mouse”, onMouseEvent )
but it just says: Undefined global Runtime. Can someone tell me what’s the problem here?

What does your listener code look like?

Here is and example with the doc links:

API Docs:

–> Click ‘mouse’ event on left side of screen:
–> Scroll to bottom of page:
-- Called when a mouse event has been received.
local function onMouseEvent( event )
    if event.type == "down" then
        if event.isPrimaryButtonDown then
            print( "Left mouse button clicked." )
        elseif event.isSecondaryButtonDown then
            print( "Right mouse button clicked." )        
-- Add the mouse event listener.
Runtime:addEventListener( "mouse", onMouseEvent )

Here is a downloadable mini project with the code above:

Run this in the simulator and choose and Android (or other non-iOS) simulated device. iOS devices do not support mouse events.

1 Like