SFML community forums

Help => Window => Topic started by: garee on June 19, 2013, 08:12:53 pm

Title: String representation of a sf::Keyboard::Key
Post by: garee 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.
}
Title: Re: String representation of a sf::Keyboard::Key
Post by: Nexus on June 19, 2013, 08:23:38 pm
Not in SFML, but in Thor (http://www.bromeon.ch/libraries/thor/v2.0/doc/_input_names_8hpp.html):
std::string s = thor::toString(sf::Keyboard::A);
Title: Re: String representation of a sf::Keyboard::Key
Post by: pbortler 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.
Title: Re: String representation of a sf::Keyboard::Key
Post by: Hapax 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? (https://github.com/Bromeon/Thor/blob/master/include/Thor/Input/InputNames.hpp#L53)

You should note also that Nexus above that mentioned it is actually the author of Thor so tends to know it quite well ;)