Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - seal

Pages: [1]
1
Window / [Solved] getting input and put them into a string
« on: February 06, 2008, 01:20:59 am »
Hello.

I want to make a textfield where I type text like any other textfield. So when a keyPress event is received I could just put the unicode character for the key in a string?
Well, I though so but that dosen't work. When I press a key that aren't a character it bugs.
So.. then I found some code from a SDL tutorial and he checked if it was a valid character, and that's what Im using.

Here's the code:
Code: [Select]

in my event loop...
                if(event.Key.Code == sf::Key::Back)     //om man tryckt på backsteg..
                {
                    if(inputField.length() > 0)
                        inputField.erase( inputField.length() - 1 );
                }
                else
                {
                    //en ifsats för att kolla att det är en bokstav eller siffra..
                    // sorry, swedish comments :P
                    if(
                    (event.Text.Unicode >= (char)'0' && event.Text.Unicode <= (char)'9')
                    ||
                    (event.Text.Unicode >= (char)'a' && event.Text.Unicode <= (char)'z')
                    ||
                    (event.Text.Unicode >= (char)'A' && event.Text.Unicode <= (char)'Z')
                    ||
                    event.Text.Unicode == (char)' '
                    )
                    {
                        inputField += (char)event.Text.Unicode;
                    }
                }
                if(event.Key.Code == sf::Key::Space)
                    inputField += (char)' ';


...
draw the text to the window.




Works really good, except when it comes to the rest of the characters I want to use, I want the user to be able to write any character..
And holding SHIFT and typing a character won't put any character in the string, why?

How would you do this?

PS, I've tried to use wxwidgets all day, but I just can't get it to work. And I just want to try to make a simple chat so I don't think I need a GUI yet.

Thanks!

Edit;
I just saw this topic:
http://sfml.sourceforge.net/forum/viewtopic.php?t=148

But it dosen't solve my problem as I want it to be able to write all characters (i.e. !"#¤%& etc), including the non-internationel ones (like å ä ö). And it dosen't work with upper case characters.

Pages: [1]