SFML community forums

Help => General => Topic started by: Nauman Ali on April 30, 2017, 06:57:37 am

Title: keyboard keys get pressed when i hover my mouse on sfml window.
Post by: Nauman Ali on April 30, 2017, 06:57:37 am
please help me with this. its my first time with sfml.

The problem is that whenever i move mouse on window keys are pressed and on left side of window escape key or return key is pressed.
Title: Re: keyboard keys get pressed when i hover my mouse on sfml window.
Post by: Hapax on April 30, 2017, 12:01:16 pm
An sf::Event is a union (http://en.cppreference.com/w/cpp/language/union) and due to this, the key code should never be queried unless the event is confirmed to be a key event type.
For example:
if (event.type == sf::Event::Keypressed)
{
    if (event.key.code == sf::Keyboard::Escape)
        escapeWasPressed();
}