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

Author Topic: Get the key pressed on keyboard  (Read 774 times)

0 Members and 1 Guest are viewing this topic.

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Get the key pressed on keyboard
« 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 !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Get the key pressed on keyboard
« Reply #1 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.
Laurent Gomila - SFML developer

 

anything