SFML community forums
Help => Window => Topic started by: didito on November 06, 2009, 12:50:55 pm
-
hi all,
i am prototyping a very simple text input application for my project
and since we are currently expecting german speaking users i need
to check for mutated vowels like ö, ä and ü. they are very important in our language and i can't use their alternatives (oe, ae or ue).
is there a way to detect them?
as event.Key.Code i always get a zero value when i press those keys on my mac...
using current revision of SFML 1.5x on macosx 10.5.8
thanks in advance
didi
-
Hi
Event::KeyPressed is not made for text input, you must use Event::TextEntered.
-
ah ok, i thought so, but i did not find any good documentation on that and the keypressed version did work properly so far.
i used this sample code i found somewhere on SFML-Dev
if (event.Type == sf::Event::TextEntered)
{
std::string ucStr;
ucStr += event.Text.Unicode;
printf("[INFO] incoming event \"TextEntered\" - %s\n", ucStr.c_str());
}
but i still get the output "[INFO] incoming event "TextEntered" - ?".
for ö, ü and ä i should not even need unicode, since they are only extended ascii and are available on every standard german keyboard.
so if i consider using textentered, how do i get the right symbols/chars then?
-
When you deal with character encoding, you have to know which encoding is used at every step.
ucStr += event.Text.Unicode;
Here, event.Text.Unicode is UTF-32 and ucStr is a 1-byte characters storage.
So you end up with latin1 (ISO-8859-1), which contains the characters of UTF-32 that can fit in 8 bits (and 1 byte is probably 8 bits on your system).
printf("[INFO] incoming event \"TextEntered\" - %s\n", ucStr.c_str());
Here you send your latin1 string to the console, which uses whatever character encoding Mac OS X likes. Probably not latin1.
-
It seems that the default encoding on Mac OS X is UTF-8. So you have to convert your string if you want to display it in the console.
However if you just need to display it in SFML (with sf::String), you won't need any conversion.
-
thank you very much for clearifying that! i definitly have a lack of knowledge in this area :oops:
i do not need this string displayed in the console, i need it on the display and the string should get converted and sent over network via UDP (mac to mac system).
and i need to process the text somehow (append character, delete last char).
so if i use sf::String and cast it to std::string will i postpone the problem and loose my symbols again?
-
so if i use sf::String and cast it to std::string will i postpone the problem and loose my symbols again?
By storing your string in std::string, you loose every character that doesn't fit in 8 bits (i.e. you work with Latin1 instead of UTF-32). But if Latin1 contains all the characters that you need, you can work with it, there's no problem (you can refer to http://en.wikipedia.org/wiki/Latin1#Codepage_layout).
If you want to support a much larger range of characters, you can use std::wstring. On Mac OS X it can store the whole UTF-32 range.