How to See if a key is down

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.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: How to See if a key is down

Post by miko »

TheP3 wrote:I want to see what key is being pressed. Without having to check isDown("a" || "b"...). Does love have some kind of function for that? Thx
What are you trying to do exactly?
You can remember keys pressed/released in a table, and just check that table, like this:

Code: Select all

function love.load()
  PRESSED={}
end

function love.draw()
  local n=0
  for k,v in pairs(PRESSED) do
    love.graphics.print(k..'=>'..v, 0, n*15)
    n=n+1
  end
end

function love.keypressed(k, u)
  PRESSED[k]=u
end

function love.keyreleased(k)
  PRESSED[k]=nil
end
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests