How to See if a key is down
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to See if a key is down
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
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
Re: How to See if a key is down
LOL I literally was typing the EXACT same question while you were typing yours.
Re: How to See if a key is down
LOL... I have to make an input field...
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: How to See if a key is down
I don't really get the question. You want to know what is pressed, but not what is down. In my mind, the two are synonymous.
Now, in regards to making a input field: use love.keypressed to get input. if it's a valid character, add it to a string. If not, do other things with it (for example, backspace would remove chars using string.sub). Profit!
Now, in regards to making a input field: use love.keypressed to get input. if it's a valid character, add it to a string. If not, do other things with it (for example, backspace would remove chars using string.sub). Profit!
Kurosuke needs beta testers
Re: How to See if a key is down
For your situation, I think there is a snippet in love.keypressed() for inputting text:
https://love2d.org/wiki/love.keypressed
And since its game-specific, I doubt you'd have a problem with just following that. Mine, on the other hand, has a few more issues to handle.
https://love2d.org/wiki/love.keypressed
And since its game-specific, I doubt you'd have a problem with just following that. Mine, on the other hand, has a few more issues to handle.
Re: How to See if a key is down
tentus wrote:I don't really get the question. You want to know what is pressed, but not what is down. In my mind, the two are synonymous.
Now, in regards to making a input field: use love.keypressed to get input. if it's a valid character, add it to a string. If not, do other things with it (for example, backspace would remove chars using string.sub). Profit!
Thanks!
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
- josefnpat
- Inner party member
- Posts: 955
- Joined: Wed Oct 05, 2011 1:36 am
- Location: your basement
- Contact:
Re: How to See if a key is down
Maybe I didn't read this thread properly, but don't you want love.keyboard.isDown( key ) ?
Missing Sentinel Software | Twitter
FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
Re: How to See if a key is down
You've got the order a bit wrong. For love.keyboard.isDown(k), you already know what key you want to check, and the return value is whether or not that specific key is pressed. It does not TELL you which key is pressed. You could supposedly use this to get it to work, but it is EXTREMELY bulky. Something like:josefnpat wrote:Maybe I didn't read this thread properly, but don't you want love.keyboard.isDown( key ) ?
Code: Select all
if love.keyboard.isDown("a") then
-- do something
elseif love.keyboard.isDown("b") then
-- do something
elseif love.keyboard.isDown("c") then
-- ...
- ston
- Prole
- Posts: 21
- Joined: Fri Jan 27, 2012 9:53 am
- Location: Holt, a small village in Wiltshire. We have cider!
Re: How to See if a key is down
It might be worth adding that if you need to check for modifiers (or more generally, more than any one key being pressed) at 'key event time' (i.e. when a key is pressed), then as far as I understand it, you'll need to add some 'is down?' checks to the keypressed() method, e.g. noddy code:
I'm just setting strings here, to illustrate the point (in .draw(), I was just printing out the 'key_pressed' string); you could set flags or take some other action as required or course :-)
Code: Select all
function love.keypressed(key)
-- check for modifiers
CTRL_KEY = ""
SHIFT_KEY = ""
ALT_KEY = ""
if love.keyboard.isDown("lctrl") or love.keyboard.isDown("rctrl") then
CTRL_KEY = "CTRL"
end
if love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift") then
SHIFT_KEY = "SHIFT"
end
if love.keyboard.isDown("lalt") or love.keyboard.isDown("ralt") then
ALT_KEY = "ALT"
end
key_pressed = CTRL_KEY .. " " .. SHIFT_KEY .. " " .. ALT_KEY .. " " .. key
end
Re: How to See if a key is down
That is a bad solution for text input boxes.
You should use the second argument to keypressed, unicode.
You should use the second argument to keypressed, unicode.
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest