[LoveFrames] KeyPress to click a button.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
dude22072
Prole
Posts: 1
Joined: Wed Jul 22, 2015 6:47 pm

[LoveFrames] KeyPress to click a button.

Post by dude22072 »

So, I'm using the loveframes library. In my game textboxes occur often so I turned displaying them into a function:

Code: Select all

function displayTextBox(inputStringArray)
    currentTextPossition = 1
    
    local textFrame = loveframes.Create("frame")
    textFrame:SetName("")
    textFrame:SetPos(0,476)
    textFrame:SetSize(640,100)
    textFrame:SetState("playing")
    textFrame:ShowCloseButton(false)
    textFrame:SetResizable(false)
    textFrame:SetDraggable(false)
    
    local listText = loveframes.Create("list", textFrame)
    listText:SetPos(0, 0)
    listText:SetSize(640, 100)
    listText:SetPadding(5)
    listText:SetSpacing(5)
    
    TextBox = loveframes.Create("text")
    TextBox:SetText(inputStringArray[currentTextPossition])
    listText:AddItem(TextBox)
    
    NextTextButton = loveframes.Create("button", textFrame)
    NextTextButton:SetText("Next")
    NextTextButton:SetPos(555,70)
    NextTextButton.OnClick = function(object)
        if inputStringArray[(currentTextPossition + 1)] ~= nil then
            currentTextPossition = currentTextPossition + 1
            TextBox:SetText(inputStringArray[currentTextPossition])
        else
            textFrame:Remove()
        end
    end
end
but, I want "NextTextButton" to also be 'click-able' by pressing a key on the keyboard. Anyone know of a good way to do this?
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: [LoveFrames] KeyPress to click a button.

Post by TurtleP »

Since NextTextButton is not a local variable, you can easily do:

Code: Select all

function love.keypressed(key)
    --change " " to any key you want, or keep is as spacebar if you want
    if key == " " then
       NextTextButton:OnClick()
    end
end
Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests