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

Author Topic: Reading single key presses  (Read 8173 times)

0 Members and 1 Guest are viewing this topic.

acrin1

  • Newbie
  • *
  • Posts: 45
    • View Profile
    • http://www.crpgdev.com
Reading single key presses
« 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

Lord Delvin

  • Jr. Member
  • **
  • Posts: 68
    • ICQ Messenger - 166781460
    • View Profile
Reading single key presses
« Reply #1 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reading single key presses
« Reply #2 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.
Laurent Gomila - SFML developer

acrin1

  • Newbie
  • *
  • Posts: 45
    • View Profile
    • http://www.crpgdev.com
Reading single key presses
« Reply #3 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.

 

anything