Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
General
»
How to tell if no key is pressed?
Print
Pages: [
1
]
Author
Topic: How to tell if no key is pressed? (Read 3986 times)
0 Members and 1 Guest are viewing this topic.
mos
Newbie
Posts: 19
How to tell if no key is pressed?
«
on:
September 03, 2016, 03:47:01 am »
I looked in the documentation (
http://www.sfml-dev.org/documentation/2.4.0/classsf_1_1Keyboard.php
) but can't seem to find anything for real time keyboard input that handles if any key is pressed or not. I am trying to make a sprite move and reset its frame in the spritesheet when nothing is pressed.
I know I can do this:
if
(
!
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
Up
)
&&
(
!
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
Down
)
&&
etc...
)
{
// Reset stuff
}
However, this will take a long time depending on how many actions there are for the sprite. Is there a faster way?
Logged
Hiura
SFML Team
Hero Member
Posts: 4321
Re: How to tell if no key is pressed?
«
Reply #1 on:
September 03, 2016, 10:53:44 am »
If it's acceptable to start the app with a key down and ignore it, then count the # of key pressed and key released event and compare them.
Otherwise, do a loop on the sf::Keyboard values (yes, you can do that, they are just named numbers).
Logged
SFML / OS X developer
Hapax
Hero Member
Posts: 3353
My number of posts is shown in hexadecimal.
Re: How to tell if no key is pressed?
«
Reply #2 on:
September 03, 2016, 08:48:02 pm »
Here is an example of looping the values.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
mos
Newbie
Posts: 19
Re: How to tell if no key is pressed?
«
Reply #3 on:
September 05, 2016, 03:36:32 am »
Thank you so much both of you! The loop works great.
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
General
»
How to tell if no key is pressed?