Search code examples
inputluakeyboardlove2d

How to do keyboard input using LÖVE?


When using LÖVE I want to change from one menu to another by hitting the ENTER key. But I only know love.keypressed, and love.keyboard.isDown.

For those two I need to hold the button down but I only want it to be pressed once. I would appreciate any help.


Solution

  • Try putting the change code in love.keyreleased()


    Something like this in main.lua

    local changeMenu =false
    
    function love.draw()
        if changeMenu then 
            -- do what you need to do
            changeMenu = false
        end
    end
    
    function love.keyreleased(key)
        if key=="return" or key=="kpenter" then
            changeMenu = true
        end 
    end