Any key using .isDown

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
Gurrlin
Prole
Posts: 6
Joined: Mon Dec 17, 2012 6:11 pm

Any key using .isDown

Post by Gurrlin »

I'm wondering how to check all keys in an efficient way using keyboard.isDown and joystick.isDown. I know these functions take multiple parameters but having to include all keys/buttons, especially the keyboard seems really awkward to me.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Any key using .isDown

Post by Robin »

It might be a better idea to use love.keypressed instead and just ignore the argument.

EDIT: or do this:

Code: Select all

local nkeysdown = 0

function love.keypressed(key, u)
    nkeysdown = nkeysdown + 1
    -- the rest of love.keypressed
end

function love.keyreleased(key, u)
    nkeysdown = nkeysdown - 1
    -- the rest of love.keyreleased
end
And then instead of having something like if love.keyboard.isDown(any) then, you do if nkeysdown > 0 then.
Help us help you: attach a .love.
Gurrlin
Prole
Posts: 6
Joined: Mon Dec 17, 2012 6:11 pm

Re: Any key using .isDown

Post by Gurrlin »

Ah, yes that makes sense, thanks!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 208 guests