SFML community forums

Help => Graphics => Topic started by: phraze on May 20, 2009, 11:25:55 am

Title: in-game console, inputting text.
Post by: phraze on May 20, 2009, 11:25:55 am
Hey, im new to SFML, and pretty new to c++.

Im currently writing on the ingame console for a game,
and im having problems figuring out how to make the text-input part.

Do i need to write some type of keymapsystem ?

Any help or maybe links to tutorials would be highly appreciated!
Title: in-game console, inputting text.
Post by: Hiura on May 20, 2009, 11:36:17 am
Use TextEntered event ( ? ) http://www.sfml-dev.org/tutorials/1.5/window-events.php
Title: in-game console, inputting text.
Post by: phraze on May 21, 2009, 08:39:31 pm
Quote from: "Hiura"
Use TextEntered event ( ? ) http://www.sfml-dev.org/tutorials/1.5/window-events.php


Okay, im going crazy about this.
How do you get exactly what is entered by text-entered ?
Title: in-game console, inputting text.
Post by: K-Bal on May 21, 2009, 08:55:25 pm
From the tutorial:

Code: [Select]
sf::Event Event;
while (App.GetEvent(Event))
{
    // Window closed
    if (Event.Type == sf::Event::Closed)
        Running = false;

    // Escape key pressed
    if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
        Running = false;
}
Title: in-game console, inputting text.
Post by: Laurent on May 21, 2009, 09:35:44 pm
Wrong. Keypress events are for key press, not for text input.

Code: [Select]
sf::Event Event;
while (App.GetEvent(Event))
{
    // Character entered
    if (Event.Type == sf::Event::TextEntered)
    {
        sf::Uint32 unicode = Event.Text.Unicode;
        ...
    }
}

What to do then with the unicode character depends on what encoding you use. If you're using ASCII, you can just cast it to char if its value is less than 128.