SFML community forums

Help => Window => Topic started by: player931402 on June 29, 2013, 12:29:21 pm

Title: handle input while window is in background
Post by: player931402 on June 29, 2013, 12:29:21 pm
hi all.

it is possible handle an input ( key press , mouse click  , and so so.. ) while sf::renderWindow is in background ?


with this code doesn't work

                sf::Event event;
                while ( window.pollEvent(event) )
                {
                        if ( event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::L  )
                        {
                              // do things
                        }
                }



it is work ony if window is focussed ! any idea ? ty in advance

C++ - sfml 2 -  visual studio 10 & 12 - OS: windows 7
Title: Re: handle input while window is in background
Post by: eXpl0it3r on June 29, 2013, 12:58:09 pm
You can use the non-event based functions from sf::Keyboard and sf::Mouse, see the documentation for more details.
Title: Re: handle input while window is in background
Post by: player931402 on June 29, 2013, 01:23:47 pm
I already know about sf::Keyboard::isKeyPressed, but there is no way using events ?
Title: Re: handle input while window is in background
Post by: The Hatchet on June 29, 2013, 02:14:09 pm
I believe events are generated for the current in-focus window.  You'd have to access the keyboard and mouse directly and check/get values yourself as stated above
Title: Re: handle input while window is in background
Post by: player931402 on June 29, 2013, 02:44:28 pm
uhm ok. I belive that u can handle an event even if the window isnt focused ( something with "lostfocus" event ).

np!! I'll use "iskeypressed" and I have to change a little bit of code.
ty all for your time.

b
Title: Re: handle input while window is in background
Post by: Laurent on June 29, 2013, 02:49:26 pm
Quote
I belive that u can handle an event even if the window isnt focused ( something with "lostfocus" event ).
Nop, the OS never sends key events to unfocused windows, this would be unnatural (that's the whole point of having a focused window). The only way to receive keyboard events while unfocused is to call a very specific function, which is not implemented in the SFML API.

Out of curiosity, why do you need that?
Title: Re: handle input while window is in background
Post by: player931402 on June 29, 2013, 04:50:10 pm
Quote
I belive that u can handle an event even if the window isnt focused ( something with "lostfocus" event ).
Nop, the OS never sends key events to unfocused windows, this would be unnatural (that's the whole point of having a focused window). The only way to receive keyboard events while unfocused is to call a very specific function, which is not implemented in the SFML API.

Out of curiosity, why do you need that?

ok gotcha, i have to find another way :)

I need to have this program running in background that can do usefull in-game macro like write pre-writed texts in game chat or save some key/mouse inputs and do it when u need and do a lot of similar things.

ty again for your time.