SFML community forums

Help => Window => Topic started by: r1nux on September 08, 2008, 11:27:22 pm

Title: sf::Input
Post by: r1nux 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.
Title: sf::Input
Post by: marox on September 09, 2008, 12:26:26 am
you can do that with Event class ;)
Title: sf::Input
Post by: r1nux 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.
Title: sf::Input
Post by: Laurent 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.