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

Author Topic: String representation of a sf::Keyboard::Key  (Read 4943 times)

0 Members and 1 Guest are viewing this topic.

garee

  • Newbie
  • *
  • Posts: 1
    • View Profile
String representation of a sf::Keyboard::Key
« on: June 19, 2013, 08:12:53 pm »
Is there a solution to computing the string representation of a sf::Keyboard::Key that doesn't involve a massive switch or if-else statement?

Ideally, I would like to avoid something like this:

const char *getKeyName(const sf::Keyboard::Key key) {
    switch(key) {
    case sf::Keyboard::Unknown:
        return "Unknown";
    case sf::Keyboard::A:
        return "A";
    case sf::Keyboard::B:
        return "B";
    case sf::Keyboard::C:
        return "C";
    // ... All the other keys.
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: String representation of a sf::Keyboard::Key
« Reply #1 on: June 19, 2013, 08:23:38 pm »
Not in SFML, but in Thor:
std::string s = thor::toString(sf::Keyboard::A);
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

pbortler

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: String representation of a sf::Keyboard::Key
« Reply #2 on: September 02, 2020, 06:02:44 pm »
I checked a few versions of Thor and none contain a toString for sf::Keyboard::Key. 
 
To all those looking for it - make your own.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: String representation of a sf::Keyboard::Key
« Reply #3 on: September 02, 2020, 08:37:18 pm »
I checked a few versions of Thor and none contain a toString for sf::Keyboard::Key. 
What do you mean?

You should note also that Nexus above that mentioned it is actually the author of Thor so tends to know it quite well ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*