1
General / Re: Relation between sf::keyboard::key and char
« on: January 27, 2015, 10:25:09 pm »Hello SFML community!
I was wondering about implementing customizable controls for a game I'm currently working on, and this question somewhat popped up on my mind: Is there any way we can convert an sf::keyboard::key (say, A) into its char/string name counterpart?
In order to create an actual options/controls screen, I'd need to be able to convert a sf::keyboard::key into a string of what it represents, which will be shown to the screen. Currently though, the only thing I can think of is manually represent each code as a specific char or string (using a ton of ifs to assign sf::keyboard::key::A into "A", sf::keyboard::key::Lshift into "Left Shift", etc).
I'm pretty sure i'm not the first to face this problem, so is there a better alternative to this?
Thanks in advance
For starters sorry for bumping old topic.
You can always cast the key. According to the API documentation they are represented as ints. So basically
char letter_a = static_cast<char>('A' + sf::Keyboard::Key::A); // Should give you 'A'.
char letter_b = static_cast<char>('A' + sf::Keyboard::Key::B); // Should give you 'B'.
// etc ...
char letter_b = static_cast<char>('A' + sf::Keyboard::Key::B); // Should give you 'B'.
// etc ...
But i guess it's dependant on your locale, etc.