SFML community forums

Help => General => Topic started by: GabrielS on June 05, 2013, 05:45:10 pm

Title: Get the key pressed on keyboard
Post by: GabrielS on June 05, 2013, 05:45:10 pm
Hello,

After reading the tutorial on event/keyboard, I was wondering if we had to make all tests like that :
Code: [Select]
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {}
Or if it was possible to get the char/stream entered on the keyboard, thus doing the test much more like that :
Code: [Select]
if (event.type == sf::Event::KeyPressed)  // in the "while (window.pollEvent(event))" loop
{
  // getKeyPressed
  // use the input on keyboard
}
Is this possible ? and if so, how can we catch this (into a sf::Text) as an example ?
If this is not possible, can I get help on how to do it manually ?

Thanks !
Title: Re: Get the key pressed on keyboard
Post by: Laurent on June 05, 2013, 06:01:27 pm
You must use the TextEntered event (see tutorial and doc), which gives you the typed characters one by one. Then it's trivial to add them to a string and display it with a sf::Text.