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

Author Topic: [SOLVED] Keyboard direct input isKeyPressed not working  (Read 2603 times)

0 Members and 1 Guest are viewing this topic.

Islander

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
[SOLVED] Keyboard direct input isKeyPressed not working
« on: July 04, 2014, 05:20:10 am »
I'm currently playing around SFML for the first time. I initially made my player movements with Events but it was always delayed. So I tried this

                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
                {
                        player.move(0, -5);
                }

This come from the documentation, but nothing move in my game.

It seems really simple, do I forget something ?

Edit : Forgot to say, its not in a PollEvent loop
« Last Edit: July 04, 2014, 05:45:17 pm by Islander »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Keyboard direct input isKeyPressed not working
« Reply #1 on: July 04, 2014, 08:01:10 am »
That's not an event, so it's correct to not put it in the pollEvent loop.

Could you show us a complete and minimal example?  Since that snippet looks fine all we can do is guess.

This is also a good opportunity to learn to use a debugger.  By setting a breakpoint on this if statement you could easily check whether or not it ever gets executed, which would help you figure out things like this yourself next time.

Islander

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Keyboard direct input isKeyPressed not working
« Reply #2 on: July 04, 2014, 05:44:58 pm »
Thanks for the reply,

I was going crazy about this yesterday (2:00AM).

This morning I found the problem, it dosen't come from the code but from a software. I use Synergy to share Keyboard / Mouse on multiple computer and it was messing with my code.

Erg, stupid mistake but atleast its now resolved.

 

anything