SFML community forums

Help => Window => Topic started by: Madras on July 27, 2012, 10:11:26 pm

Title: [SFML 2.0] Why isKeyPressed isn't working immediately
Post by: Madras on July 27, 2012, 10:11:26 pm
Hi! I have been still experimenting since few days with SFML. Yesterdey I moved from 1.6 to 2.0 version. In the earlier SFML I used GetInput() and IsKeyDown, everything was OK. In latest one, there's no GetInput, so I used isKeyPressed event. Unfortunately when I'm pressing any key, isKeyPressed makes 'tick', ... waits few ms ... and continues working. I dont know, how did you eliminated this aspect in Pong game for example.

I hope that you understand what I mean.  Thanks for helping. :)
Title: Re: [SFML 2.0] Why isKeyPressed isn't working immediately
Post by: Perde on July 27, 2012, 11:28:52 pm
There is no isKeyPressed in sf::Event (IIRC), but in sf::Keyboard (what you should be using for that sort of thing), which kind of replaces sf::Input from SFML 1.6.
As far as I understand it, events shouldn't be used for that kind of direct input.
Title: Re: [SFML 2.0] Why isKeyPressed isn't working immediately
Post by: eXpl0it3r on July 27, 2012, 11:29:57 pm
That's what your OS does to key events (e.g. hold down a key in a textbox and notice the same behaviour, lucky otherwise you'd be constantly entering double, tripple, etc. letters.

GetInput() was removed but replaced by a better way of handeling inputs. There are now the classes sf::Mouse, sf::Keyboard and sf::Joystick. The one in the middel is the one you want.
The usage is quite similar to the old SFML 1.6:
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) ) sprite.move( -1.f, 0.f );

There is no isKeyPressed in sf::Event (IIRC)
There's sf::Event::KeyPressed and sf::Event::KeyReleased. ;)
But yes for direct input the event system shouldn't be used.
Title: Re: [SFML 2.0] Why isKeyPressed isn't working immediately
Post by: Perde on July 28, 2012, 12:24:18 am
There is no isKeyPressed in sf::Event (IIRC)
There's sf::Event::KeyPressed and sf::Event::KeyReleased. ;)

I don't see how that contradicts my statement.  :P
Title: Re: [SFML 2.0] Why isKeyPressed isn't working immediately
Post by: eXpl0it3r on July 28, 2012, 12:53:49 am
I don't see how that contradicts my statement.  :P
It didn't I just confirmed it, thus removing the IIRC and completed the statement by providing the existing constants. ;)
Title: Re: [SFML 2.0] Why isKeyPressed isn't working immediately
Post by: Madras on July 28, 2012, 01:00:10 am
WOW! Three replies :D

Now my friends I know where was mistake! The isKeyPressed wasn't working immediately bacause I put it in events loop. Now when I moved outside loop it works brilliant, did the trick, hehe.

Thank you so much, again!