SFML community forums
Help => Window => Topic started by: mutonizer on July 20, 2012, 09:07:15 am
-
Morning,
Are there any SFML 2.0 function (or logic) to convert the sf::keyboard enum to an ASCI or UNICODE character table?
The idea is to be able to initialize a class (which is just to display sf:text, but with all events handling taken care of, etc) with a character, to make it a shortcut, and have the class handle the function to automatically edit the text and make all appropriate changes, like adding for example a "a) " in front of the current label text if we set that shortcut to "a", then react through events using sf::keyboard isPressed.
I've been using sf::keyboard to avoid tons of boolean stuff everytime sf::event:keyPressed pops up, but I'm having issues finding a logical conversion between the actual UNICODE key code, and sf::keyboard enum values and I can't just initialize with the enum directly, since I need to display the character in question.
So the question is, before I start doing my personal conversion function, is there already one in place?
-
Use the sf::Event::TextEntered for text input, not key press.
-
Hey,
err, I do, but fail to see how it relates to what I posted. Probably didn't explain myself properly. :)
Say I want the user to be able to press A and click somewhere, and it does something.
Instead of storing a bool on keypress/keyrelease, I wanted to use sf::keyboard, which gives direct access to the keyboard state so I can just, on the Mousebutton event, check if sf::keyboard::a is pressed and that's it.
But add to that for example that I want to display, on click, the letter A somewhere (or any letter being pressed when mousebutton event pops up). My problem is that from the mousebutton event (where action is taken), I can know if the letter A is pressed, but how can I use that information, to know which letter to display?
I could make my own conversion function, inputting the sf::keyboard value and returning the converted ASCI value, but is there already such conversion function or any logic to the sf::keyboard enum relating to the ASCI/UNICODE tables?
-
No, there's no such function. You have to write it with a big switch.
-
You have to write it with a big switch.
Or figure out a formula that converts key codes from the key enum to your chars.
-
Or figure out a formula that converts key codes from the key enum to your chars.
How? SFML key codes are defined randomly and might change in the future. You can't find a single formula that maps all key codes to ASCII/Unicode values. You must map them one by one.
-
Cheers.
Just wanted to be sure to avoid doing it only to find out later on that it was already present.
-
I could make my own conversion function, inputting the sf::keyboard value and returning the converted ASCI value, but is there already such conversion function or any logic to the sf::keyboard enum relating to the ASCI/UNICODE tables?
You can take a look at Thor's InputNames (http://www.bromeon.ch/libraries/thor/v2.0/doc/_input_names_8hpp.html). The functions map the keys and mouse buttons to a string (the enumerator name) or vice versa.