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

Author Topic: handle input while window is in background  (Read 3987 times)

0 Members and 1 Guest are viewing this topic.

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
handle input while window is in background
« 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
« Last Edit: June 29, 2013, 12:34:52 pm by player931402 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: handle input while window is in background
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: handle input while window is in background
« Reply #2 on: June 29, 2013, 01:23:47 pm »
I already know about sf::Keyboard::isKeyPressed, but there is no way using events ?

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: handle input while window is in background
« Reply #3 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

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: handle input while window is in background
« Reply #4 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: handle input while window is in background
« Reply #5 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?
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: handle input while window is in background
« Reply #6 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.