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

Author Topic: Single key press outside a sfml window?  (Read 2643 times)

0 Members and 1 Guest are viewing this topic.

KKZiomek

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Single key press outside a sfml window?
« on: December 28, 2016, 07:29:00 am »
I recently wondered if there is a function in SFML that can detect if a key was pressed once but outside an event of a window. I would want do detevt this outside a sfml window. sf::isKeyPressed only detects if a key is held, but not pressed.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Single key press outside a sfml window?
« Reply #1 on: December 28, 2016, 07:44:18 am »
What do you mean under "detecting outside the window"?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Single key press outside a sfml window?
« Reply #2 on: December 28, 2016, 08:48:41 am »
There isn't. Events are window based and sf::Keyboard does real-time checks.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

KKZiomek

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Single key press outside a sfml window?
« Reply #3 on: December 28, 2016, 04:43:06 pm »
Can anyone think of any way to turn those "id held" statements into single keypresses?

I did:

//Pseudocode
while isKeyPressed(Key)
{
        if not isKeyPressed(Key) break;
}

But this is not good, as other keys are not detected and program is delayed.

Can anyone think of better way?
« Last Edit: December 28, 2016, 04:45:08 pm by KKZiomek »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Single key press outside a sfml window?
« Reply #4 on: December 28, 2016, 07:29:23 pm »
You need to store the previous state of the key. Then compare it to the current state: if they are different, then the key is either pressed or released.
Laurent Gomila - SFML developer