Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Window
»
Text entered but update when keyreleased
Print
Pages: [
1
]
Author
Topic: Text entered but update when keyreleased (Read 3077 times)
0 Members and 1 Guest are viewing this topic.
Qluxzz
Guest
Text entered but update when keyreleased
«
on:
May 11, 2013, 02:10:26 pm »
Hi there I'm working on a textbox where the user enters its name. The problem I'm having is that a soon as i press a key it writes out the character about five times in a row. That's why I just want it to enter a character when the user releases the key.
if
(
mainEvent.
type
==
sf
::
Event
::
TextEntered
)
{
char
c
=
static_cast
<
char
>
(
mainEvent.
text
.
unicode
)
;
if
(
c
>=
'A'
&&
c
<=
'z'
)
{
// Add the new character to the string
str
=
c
;
// Set the string to name
nameString
+
=
str
;
name.
setString
(
nameString
)
;
cout
<<
nameString
;
}
}
Thanks in advance
Logged
AlexAUT
Sr. Member
Posts: 396
Re: Text entered but update when keyreleased
«
Reply #1 on:
May 11, 2013, 02:22:00 pm »
If you really only want 1 character each KeyPressed you could use "window.setKeyRepeatEnabled(false);"
But normally sf::Event::TextEntered return the character only once and when you hold the key longer than (i guess 1second) it will start "spamming" the character, like every Windows Inputbox does.
AlexAUT
Logged
Android (Play Store):
https://play.google.com/store/apps/details?id=com.alexaut.kroniax.android
Laurent
Administrator
Hero Member
Posts: 32498
Re: Text entered but update when keyreleased
«
Reply #2 on:
May 11, 2013, 03:27:21 pm »
Can you show the surrounding code? The complete event loop would be great (I don't care about other events, I just want to see how/where your code block is executed).
Logged
Laurent Gomila - SFML developer
Laurent
Administrator
Hero Member
Posts: 32498
Re: Text entered but update when keyreleased
«
Reply #3 on:
May 11, 2013, 04:44:41 pm »
Can you show the calling code? I'd like to see where the event instance comes from.
Logged
Laurent Gomila - SFML developer
Laurent
Administrator
Hero Member
Posts: 32498
Re: Text entered but update when keyreleased
«
Reply #4 on:
May 11, 2013, 07:13:27 pm »
Ok, let's be more explicit. The event instance is initialized by a call to window.pollEvent. I want to see this call, and what happens to the event until it reaches userInput
Logged
Laurent Gomila - SFML developer
Laurent
Administrator
Hero Member
Posts: 32498
Re: Text entered but update when keyreleased
«
Reply #5 on:
May 11, 2013, 08:46:31 pm »
Any usage of mainEvent should happen inside the event loop. Outside, its contents are undefined, or if it has a wider scope, it will always be the last event that happened repeating again and again -- which explains your problem.
Logged
Laurent Gomila - SFML developer
Print
Pages: [
1
]
SFML community forums
»
Help
»
Window
»
Text entered but update when keyreleased
anything