Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SFML 2.0] Why isKeyPressed isn't working immediately  (Read 3607 times)

0 Members and 1 Guest are viewing this topic.

Madras

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
[SFML 2.0] Why isKeyPressed isn't working immediately
« 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. :)

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: [SFML 2.0] Why isKeyPressed isn't working immediately
« Reply #1 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: [SFML 2.0] Why isKeyPressed isn't working immediately
« Reply #2 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.
« Last Edit: July 27, 2012, 11:31:40 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: [SFML 2.0] Why isKeyPressed isn't working immediately
« Reply #3 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: [SFML 2.0] Why isKeyPressed isn't working immediately
« Reply #4 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. ;)
« Last Edit: July 28, 2012, 12:55:27 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Madras

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: [SFML 2.0] Why isKeyPressed isn't working immediately
« Reply #5 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!
« Last Edit: July 28, 2012, 01:02:21 am by Madras »

 

anything