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

Author Topic: Get the char of key pressed  (Read 12009 times)

0 Members and 1 Guest are viewing this topic.

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Get the char of key pressed
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Get the char of key pressed
« Reply #1 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).
Laurent Gomila - SFML developer

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Get the char of key pressed
« Reply #2 on: December 11, 2009, 04:05:39 pm »
Sorry, but i'm inexperient, how do i make this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Get the char of key pressed
« Reply #3 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?
Laurent Gomila - SFML developer

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Get the char of key pressed
« Reply #4 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?

Nothingness0x

  • Sr. Member
  • ****
  • Posts: 292
    • View Profile
Get the char of key pressed
« Reply #5 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Get the char of key pressed
« Reply #6 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?
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Get the char of key pressed
« Reply #7 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...
Laurent Gomila - SFML developer

Nothingness0x

  • Sr. Member
  • ****
  • Posts: 292
    • View Profile
Get the char of key pressed
« Reply #8 on: December 11, 2009, 04:44:38 pm »
Sorry didn't see  :lol:

Nothingness0x

  • Sr. Member
  • ****
  • Posts: 292
    • View Profile
Get the char of key pressed
« Reply #9 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 ?

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Get the char of key pressed
« Reply #10 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++;
                    }
                }
            }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Get the char of key pressed
« Reply #11 on: December 11, 2009, 05:08:17 pm »
You must forget sf::Event::KeyPressed and use sf::Event::TextEntered.
Laurent Gomila - SFML developer