SFML community forums

Help => Window => Topic started by: acrin1 on October 21, 2007, 11:01:22 am

Title: Reading single key presses
Post by: acrin1 on October 21, 2007, 11:01:22 am
I'm reading the keyboard like so:

if (App.GetInput().IsKeyDown(sf::Key::F11)) ToggleInsMode();
if (App.GetInput().IsKeyDown(sf::Key::F10)) ToggleItemMode();

This is working ok but this method is reading the key continuously until the key is released. What's the best way to read a single keypress or turn off the continuous reading of keys?

Thanks
Title: Reading single key presses
Post by: Lord Delvin on October 21, 2007, 11:05:55 am
You could fire an event in your system if the key is known to be pressed the first frame and only use that event for calculations.
Title: Reading single key presses
Post by: Laurent on October 21, 2007, 03:31:00 pm
sf::Input is for reading real-time (continuous) inputs. It shouldn't be used to get single events like key presses.

Use the sf::Event::KeyPressed event instead.
Title: Reading single key presses
Post by: acrin1 on October 22, 2007, 08:58:14 pm
Quote from: "Laurent"
sf::Input is for reading real-time (continuous) inputs. It shouldn't be used to get single events like key presses.

Use the sf::Event::KeyPressed event instead.

Thanks. I missed that in the tutorial.