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

Author Topic: See if a user is holding a key?  (Read 1106 times)

0 Members and 1 Guest are viewing this topic.

BeautiCode

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
See if a user is holding a key?
« on: June 29, 2014, 03:28:06 am »
How do I tell whether the user is holding a key down, in the normal event handling loop?
I just use a switch/case statement and do an action based upon if the key is pressed. But I wanna repeatedly do that action as long as the key is being held down. Could someone provide an example?

BeautiCode

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: See if a user is holding a key?
« Reply #1 on: June 29, 2014, 03:45:37 am »
Well nevermind I noticed that it automatically does that. But what about if the user is holding down 2 keys at once?

G.

  • Hero Member
  • *****
  • Posts: 1559
    • View Profile
Re: See if a user is holding a key?
« Reply #2 on: June 29, 2014, 04:46:37 am »
You can use sf::Keyboard::IsKeyPressed. It returns true as long as the specified key is held down.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
...
}

BeautiCode

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: See if a user is holding a key?
« Reply #3 on: June 29, 2014, 04:54:48 am »
You can use sf::Keyboard::IsKeyPressed. It returns true as long as the specified key is held down.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
...
}
Thanks