Hello,
I've been following Love's progress for a while and finally got a chance to start a game with it. I was wondering if there was a way to get all the keys currently pressed, instead of having to check each key that you cared about? I couldn't find anything on the wiki or searching the forums.
Get all keys currently pressed
Get all keys currently pressed
----------------------------------------
Sluicer Games
Sluicer Games
Re: Get all keys currently pressed
As far as I'm aware, you can't do it in one go. It's possible (but perhaps unnecessary) to test for EVERY key with
but I don't think that would help at all. Honestly, I like the way LOVE handles keyboard input, because you end up not having to test for keypress every frame as it just triggers the event with the callback function love.keypressed( key)
For a different perspective on dealing with keypress, there's a nice article here. There are also some libraries made by LOVE users, to simplify key binding, etc - just check the Wiki.
Good luck.
Code: Select all
love.keyboard.isDown( key )
For a different perspective on dealing with keypress, there's a nice article here. There are also some libraries made by LOVE users, to simplify key binding, etc - just check the Wiki.
Good luck.
Did my comment help/offended you? Use the Karma button!!
LÖVEing each day...
LÖVEing each day...
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Get all keys currently pressed
Forget about love.keyboard. Use love.keypressed and love.keyreleased to update a table instead.
Example (download and change extension to .zip to see the contents):
Note that the amount of simultaneously pressed keys is limited to between 3 and 6 - that's a limitation on your hardware or operative system that love can't overcome.
Example (download and change extension to .zip to see the contents):
Note that the amount of simultaneously pressed keys is limited to between 3 and 6 - that's a limitation on your hardware or operative system that love can't overcome.
When I write def I mean function.
Re: Get all keys currently pressed
Code: Select all
KeysPressed = {}
function love.keypressed(a, b)
KeysPressed[a]=b
end
function love.keyreleased(a)
KeysPressed[a] = nil
end
Lua is not an acronym.
Re: Get all keys currently pressed
wow, nice kikito, I hadn't thought of handling it like that! We keep on learning...
Did my comment help/offended you? Use the Karma button!!
LÖVEing each day...
LÖVEing each day...
Re: Get all keys currently pressed
Ah! Great solution, thanks kikito!
----------------------------------------
Sluicer Games
Sluicer Games
Re: Get all keys currently pressed
I managed to press 9 keys at once.kikito wrote:Forget about love.keyboard. Use love.keypressed and love.keyreleased to update a table instead.
Example (download and change extension to .zip to see the contents):
Note that the amount of simultaneously pressed keys is limited to between 3 and 6 - that's a limitation on your hardware or operative system that love can't overcome.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Get all keys currently pressed
I think it depends on your individual hardware. Macbook Pro keyboards seem to have some strange rules here, I seem to be able to press combinations depending no the x and y, if you will, of the keys already pressed. Also the arrow keys only seems to allow 2 arrow keys to be down at a time.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Get all keys currently pressed
Most keyboards divide the keys into groups, and there's a limit to the amount of keys you can press within a group. (And therefore the amount of keys in total.)
Re: Get all keys currently pressed
How would you adapt this for the joystick module to see what buttons are currently being pressed?kikito wrote:Forget about love.keyboard. Use [wiki]love.keypressed[/wiki] and [wiki]love.keyreleased[/wiki] to update a table instead.
Example (download and change extension to .zip to see the contents):
Note that the amount of simultaneously pressed keys is limited to between 3 and 6 - that's a limitation on your hardware or operative system that love can't overcome.
EDIT: ah, just found love.joystickpressed and released, nevermind!
Who is online
Users browsing this forum: Bing [Bot] and 2 guests