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

Author Topic: sf::RenderWindow responds to clicks, on background ...  (Read 1955 times)

0 Members and 1 Guest are viewing this topic.

Léandre

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
sf::RenderWindow responds to clicks, on background ...
« on: July 26, 2017, 02:23:00 pm »
Hi,

I'm not really new with sfml, but was using CSFML, well now I'm learning C++ and doin pretty well,
So I'm creating a tiny game, where I need to handle mouse position, my main problem is that, even if I'm focused
in a Terminal of other software, the window still responds in background, so I can click on the sfml window, while being in my C++ code for example.
Hum, is there any way to avoid this ? Because I'm using isKeyPressed and isMousePressed so maybe witch the events ?

Best regards,
Léandre

Léandre

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: sf::RenderWindow responds to clicks, on background ...
« Reply #1 on: July 26, 2017, 02:25:07 pm »
Nevermind, I've found the LostFocus event

Hapax

  • Hero Member
  • *****
  • Posts: 3353
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::RenderWindow responds to clicks, on background ...
« Reply #2 on: July 27, 2017, 11:33:37 pm »
LostFocus and GainedFocus can solve your problem but you will have to track the focus state to know whether it's currently in focus or not (it would only need a simple boolean, of course).

However, and especially since you're using real-time states, you may also be interested in hasFocus, which can inform you of the current state of focus.

e.g.
if (window.hasFocus())
{
    if (isKeyPressed(sf::Keyboard::Up))
        moveUp();
    if (isKeyPressed(sf::Keyboard::Down))
        moveDown();
    // etc.
}
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*