SFML community forums

Help => Window => Topic started by: Sebox on September 23, 2014, 05:34:01 pm

Title: Active event
Post by: Sebox on September 23, 2014, 05:34:01 pm
Hello everyone!

I have problem with event. I have to make program which can receive event when the window is inactive and active. For example: i run the program and click something in keyboard - ok now its work but when i minimize the program, the event doesn't work i dont have idea how to solve.

Thanks in advance for your answers.
Title: Re: Active event
Post by: AlexAUT on September 23, 2014, 05:37:29 pm
This is not possible with events, but you can access with sf::Mouse/Keyboard/Joystick/Sensor the state of the hardware (even if the window is in background afaik you do not even need a window) and check if something has changed since the last frame. Have a look at the tutorials: http://sfml-dev.org/tutorials/2.1/window-inputs.php


AlexAUT
Title: Re: Active event
Post by: zsbzsb on September 23, 2014, 06:16:02 pm
Its not entirely impossible, but to do something like this you can't use SFML, you will need to write your own platform specific code.
Title: Re: Active event
Post by: Sebox on September 23, 2014, 06:25:01 pm
Yes i saw this way but when i click something the program receive several times this sign, because i click this at some time and processor many times it took. So i think i need something like but no (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  but (sf::Keyboard::isKeyReleased(sf::Keyboard::Left))  but i dont know if such a thing exists.
Title: Re: Active event
Post by: AlexAUT on September 23, 2014, 06:36:30 pm
Thats why i wrote

Quote
check if something has changed since the last frame

For example if you want to check if "Return" got pressed/released:

void checkReturnKey()
{
     static bool lastState = false;
     bool currentState = sf::Keyboard::isKeyPressed(sf::Keyboard::Return);

     if(!lastState && currentState)
          //Got pressed
     else if(lastState && !currentState)
          //Got released      

     lastState = currentState
}
 

With this code "Pressed"/"Released" will only get called 1time like with events.


AlexAUT
Title: Re: Active event
Post by: Sebox on September 23, 2014, 06:54:19 pm
Thanks for help but i think its not be sufficient precision what it needs, so if event dont be work in minimize i think i have to look for other way  :(