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

Author Topic: sf::Input  (Read 3970 times)

0 Members and 1 Guest are viewing this topic.

r1nux

  • Newbie
  • *
  • Posts: 9
    • View Profile
sf::Input
« on: September 08, 2008, 11:27:22 pm »
I'm looking for the feature to not only read out if a key is pressed (with App.GetInput()).

In my utopia the Input-class would have the following functions:
IsKeyDown (only returns true the first time a key is being pressed)
IsKeyPressed (returns true every time a key is pressed)
IsKeyReleased (returns true when and only when the key has been released)

I have tried to "simulate" this by myself but without success.
If anyone could help me simulate this or point me in the right direction
I would happily be satisfied with that.

Best regards.

marox

  • Full Member
  • ***
  • Posts: 178
    • View Profile
sf::Input
« Reply #1 on: September 09, 2008, 12:26:26 am »
you can do that with Event class ;)
mon tout nouveau siteweb  : Creations

r1nux

  • Newbie
  • *
  • Posts: 9
    • View Profile
sf::Input
« Reply #2 on: September 09, 2008, 06:14:21 am »
Quote from: "marox"
you can do that with Event class ;)


Ahh, thats true.
Tho im still not getting hang of how to implement a check for a single keypress.
What I'm meaning with that is that i want to seperate
onKeyPress and onKeyDown.
Hard to explain and definitive in the wrong forum-section for this kind of topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Input
« Reply #3 on: September 09, 2008, 08:38:08 am »
Key down is a state, you can request it anytime :
Code: [Select]
bool KeyDown = Win.GetInput().IsKeyDown(sf::Key::xxx);
bool KeyUp = !Win.GetInput().IsKeyDown(sf::Key::yyy);


While key press is an event, it happens once and it wouldn't make sense to request it; instead you're notified when it happens :
Code: [Select]
sf::Event Event;
while (Win.GetEvent(Event))
{
    if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::xxx))
    {
        ...
    }
}

This is well explained in the tutorials.
Laurent Gomila - SFML developer

 

anything