Solar2D onKeyEvent returns "nil"

Hello :slight_smile:
I’m using the Linux version of Solar2D so this could be a Linux implementation issue:
I’m running the following simple code:

local function onKeyEvent (event)
    print (event.KeyName)
    --balloon:setLinearVelocity(-40,0)
    if event.KeyName == "a" then
        balloon:setLinearVelocity(-40,0)
    end
end

Runtime:addEventListener("key", onKeyEvent)

I’ve only just noticed that this is not making my balloon start to drift left because pressing any keyboard key returns “nil” and not the key name I pressed.

Is there something else I have missed or do I just need to switch to a Windows computer?

Thanks

Try use event.keyName instead event.KeyName.

Argh, silly me! Yep, typical user error. Thanks so much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.