Mousepressed and Keypressed=> TextInput

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
TheScriptan
Citizen
Posts: 56
Joined: Wed Feb 27, 2013 7:53 pm

Mousepressed and Keypressed=> TextInput

Post by TheScriptan »

Hello everyone! So I followed some tutorials where there was a function Mousepressed, but this function I think is deleted and it's not mentioned in the wiki!:)

I am new to Love2D and I saw one change here: KeyPressed to textinput. So I can't get the input work with textinput, maybe some of you could give me a simple example of user input using textinput function? :)
User avatar
SneakySnake
Citizen
Posts: 94
Joined: Fri May 31, 2013 2:01 pm
Contact:

Re: Mousepressed and Keypressed=> TextInput

Post by SneakySnake »

TheScriptan wrote:So I followed some tutorials where there was a function Mousepressed, but this function I think is deleted and it's not mentioned in the wiki!:)
It wasn't deleted. It still exists.
TheScriptan wrote:I am new to Love2D and I saw one change here: KeyPressed to textinput.
textinput is not a replacement of keypressed. keypressed still exists.

LÖVE 0.9.1 code

Code: Select all

local log = {}

function love.load()
    love.keyboard.setKeyRepeat(true)
end

function love.mousepressed(x, y, button)
    table.insert(log, string.format("Mouse button %s pressed at %s, %s", button, x, y))
end

function love.keypressed(key, isrepeat)
    local r = isrepeat and "It's a repeat" or "Not a repeat"
    table.insert(log, string.format("Key %s pressed, %s", key, r))
end

function love.draw()
    for i, v in ipairs(log) do
        love.graphics.print(v, 0, (i - 1) * love.graphics.getFont():getHeight())
    end
end

TheScriptan
Citizen
Posts: 56
Joined: Wed Feb 27, 2013 7:53 pm

Re: Mousepressed and Keypressed=> TextInput

Post by TheScriptan »

EDIT:
Sorry, I didn't notice that there is a variable in keypressed function that is required! Thank you for the information! :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest