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

Author Topic: Text Input  (Read 6824 times)

0 Members and 2 Guests are viewing this topic.

aaroncm

  • Newbie
  • *
  • Posts: 20
    • View Profile
Text Input
« 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 =)

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text Input
« Reply #1 on: October 28, 2012, 01:49:16 am »
Maybe your string keeps going out of scope, show the event loop.
Back to C++ gamedev with SFML in May 2023

aaroncm

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Text Input
« Reply #2 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 :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Text Input
« Reply #3 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...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text Input
« Reply #4 on: October 28, 2012, 02:26:46 am »
Try adding  if (event.text.unicode < 128) like tutorials says.
Back to C++ gamedev with SFML in May 2023

aaroncm

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Text Input
« Reply #5 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

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Re: Text Input
« Reply #6 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.

aaroncm

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Text Input
« Reply #7 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.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Re: Text Input
« Reply #8 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 which as well as covering the event loop has a section dedicated to TextEntered.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text Input
« Reply #9 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
Laurent Gomila - SFML developer

aaroncm

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Text Input
« Reply #10 on: October 28, 2012, 11:40:41 am »
So I was polling the event incorrectly. Thanks, working now.