SFML community forums

Help => Window => Topic started by: Gregory on December 11, 2009, 02:36:34 pm

Title: Get the char of key pressed
Post by: Gregory on December 11, 2009, 02:36:34 pm
how do i get a char or pointer to char of the last key pressed in ACSII, to make a text box?
Title: Get the char of key pressed
Post by: Laurent on December 11, 2009, 02:41:17 pm
You must catch the sf::Event::TextEntered event, which gives you the character in event.Text.Unicode. This is a UTF-32 character, but you can safely cast it to a char if it is < 128 (ie. in the ASCII range).
Title: Get the char of key pressed
Post by: Gregory on December 11, 2009, 04:05:39 pm
Sorry, but i'm inexperient, how do i make this?
Title: Get the char of key pressed
Post by: Laurent on December 11, 2009, 04:10:54 pm
Did you first read the tutorials, to learn how to write a game and event loop? What problems do you get exactly?
Title: Get the char of key pressed
Post by: Gregory on December 11, 2009, 04:38:41 pm
I'm make a very good online game, the problem is not this, i'm brazilian and my english is not very good, can you write the code for i make that you speaked?
Title: Get the char of key pressed
Post by: Nothingness0x on December 11, 2009, 04:41:30 pm
I think he just wanna use the TextEntered event

You've gotta use sf::Event::TextEntered.
Then use Event.Text.Unicode to add the new letter entered to your string
Title: Get the char of key pressed
Post by: Laurent on December 11, 2009, 04:42:45 pm
Well, no. I prefer taking time to explain what you don't understand, rather than providing you with a source code that you can copy-and-paste directly in your code.

So, what did you try? What code do you already have? What don't you understand?
Title: Get the char of key pressed
Post by: Laurent on December 11, 2009, 04:43:17 pm
Quote from: "Nothingness0x"
I think he just wanna use the TextEntered event

You've gotta use sf::Event::TextEntered.
Then use Event.Text.Unicode to add the new letter entered to your string

This is exactly what I first said...
Title: Get the char of key pressed
Post by: Nothingness0x on December 11, 2009, 04:44:38 pm
Sorry didn't see  :lol:
Title: Get the char of key pressed
Post by: Nothingness0x on December 11, 2009, 04:47:51 pm
Gregory what about posting your code so we can see where you're stuck in order to help you out ?
Title: Get the char of key pressed
Post by: Gregory on December 11, 2009, 05:02:01 pm
Code: [Select]
if (myevent.Type == sf::Event::KeyPressed and state == 0 and tempo_novo != -1 and myevent.Key.Code == sf::Key::A) {
                if (myevent.Key.Code == sf::Key::BackSlash) {
                    pos_cur--;
                    nome_digit[pos_cur+1] = '\0';
                }
                else {
                    nome_digit[pos_cur] = myevent.Key.Code;
                    nome_digit[pos_cur+1] = '\0';
                    nome_str = nome_digit;
                    record_name[tempo_novo] = nome_str;
                    if (pos_cur < 13) {
                        pos_cur++;
                    }
                }
            }
Title: Get the char of key pressed
Post by: Laurent on December 11, 2009, 05:08:17 pm
You must forget sf::Event::KeyPressed and use sf::Event::TextEntered.