SFML community forums

Help => General => Topic started by: aaroncm on October 28, 2012, 01:42:39 am

Title: Text Input
Post by: aaroncm on October 28, 2012, 01:42:39 am
Hey guys. Having a little trouble with text input, using the TextEntered event.
I can't seem to get any characters added to the string. The only way I can is if I use Event::KeyPressed, which inserts unknown [] characters.

I'm using str += static_cast<char>(tInput.text.unicode); with SFML 2.0.

Thanks in advance =)
Title: Re: Text Input
Post by: FRex on October 28, 2012, 01:49:16 am
Maybe your string keeps going out of scope, show the event loop.
Title: Re: Text Input
Post by: aaroncm on October 28, 2012, 02:13:28 am
Hmm no they're in scope. The strings are created outside of a while(window->isOpen()) loop.

Thanks :)
Title: AW: Text Input
Post by: eXpl0it3r on October 28, 2012, 02:24:00 am
I guess that static cast of a unicode (w_char or similar) can't be performed and if so I wouldn't know what the output should be...
Title: Re: Text Input
Post by: FRex on October 28, 2012, 02:26:46 am
Try adding  if (event.text.unicode < 128) like tutorials says.
Title: Re: Text Input
Post by: aaroncm on October 28, 2012, 02:10:09 am
Oh I have that =)

Yeah, it's like it's getting the unicode fine, but I can't get it to normal characters ascii
Title: Re: Text Input
Post by: Walker on October 28, 2012, 04:30:41 am
A minimal example would have avoided all the guessing and you'd probably have your answer by now.

I'm going to guess that your keyboard is faulty.
Title: Re: Text Input
Post by: aaroncm on October 28, 2012, 10:25:49 am
-_-

Event tInput;
window->pollEvent(tInput);
if (tInput.type == sf::Event::TextEntered) {
        if (tInput.text.unicode < 128) {
                str += static_cast<char>(tInput.TextEntered);                  
        }
}
cBox.setString(str);
window->draw(cBox);
 

Thats probably not exactly like the example that I found on this forum earlier, that is just what I had saved at the time I posted this after trying everything I could think of.
Title: Re: Text Input
Post by: Walker on October 28, 2012, 11:14:59 am
That's not a minimal example. If that's how your event handling looks, you should probably follow the events tutorial: http://www.sfml-dev.org/tutorials/2.0/window-events.php (http://www.sfml-dev.org/tutorials/2.0/window-events.php) which as well as covering the event loop has a section dedicated to TextEntered.
Title: Re: Text Input
Post by: Laurent on October 28, 2012, 11:39:48 am
What kind of help you do expect to get if you don't show us your code (the real one, not a buggy equivalent)? :P
Title: Re: Text Input
Post by: aaroncm on October 28, 2012, 11:40:41 am
So I was polling the event incorrectly. Thanks, working now.