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

Author Topic: [SOLVED] How to know when a key is released when I'm pressing two keys?  (Read 4091 times)

0 Members and 2 Guests are viewing this topic.

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
When there is only one key I use this function to check when one key is released:

if (GameApp::event.type == sf::Event::KeyReleased && GameApp::event.key.code == sf::Keyboard::Right)
{

}
 

But when there are two keys pressed at the same time and I release one the event it's not handled.


PD: Sorry it's solved, the code works but I was checking inside a function that it's executed only when a key it's pressed so  I wrote again the function.
« Last Edit: January 25, 2015, 07:18:58 pm by Laurent »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How to know when a key is released when I'm pressing two keys?
« Reply #1 on: January 25, 2015, 03:41:51 pm »
In general, it's pretty simple to keep track of keys yourself. Since you get an event on every key up/down it is fairly simple to keep track of "all keys currently pressed".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to know when a key is released when I'm pressing two keys?
« Reply #2 on: January 25, 2015, 06:34:41 pm »
In case you didn't notice, he already solved his problem.
Laurent Gomila - SFML developer

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How to know when a key is released when I'm pressing two keys?
« Reply #3 on: January 25, 2015, 07:10:45 pm »
Whoops. Missed that.