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

Author Topic: Active event  (Read 2740 times)

0 Members and 1 Guest are viewing this topic.

Sebox

  • Newbie
  • *
  • Posts: 24
    • View Profile
Active event
« 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.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Active event
« Reply #1 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

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Active event
« Reply #2 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Sebox

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Active event
« Reply #3 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.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Active event
« Reply #4 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

Sebox

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Active event
« Reply #5 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  :(