SFML community forums
Help => Window => Topic started by: yoni0505 on December 25, 2010, 09:32:42 pm
-
I'm making a text input field and I want to delete the last char in a string when the user press BACKSPACE.
For some reason it isn't working right:
When I press BACKSPACE it will only delete one char then it will not delete anything untill I enter a new char to the string.
Im using this function to delete the last char:
void CheckKeyPressed(CField* Field, sf::Event::KeyEvent* Key)
{
if(Key->Code == sf::Key::Back)
{
Field->str = Field->str.substr(0, Field->str.length() - 1);
}
}
I know that the EnableKeyRepeat is true by default.
Why it doesn't work right? :?
-
Why dont you test it further? I think that most of the people should debug deeper and smarter for a time before posting a question..
Check if other keys are repeating, for example. Check if you function is called as it should, etc.
-
Why dont you test it further? I think that most of the people should debug deeper and smarter for a time before posting a question..
Check if other keys are repeating, for example. Check if you function is called as it should, etc.
Of course I tested it and debugged it as best as I could, googled for answer but didn't find any.
I can't find a reason why this thing happening, after all it works after I enter a new char to the string.
I wouldn't ask in the forums unless I reach a dead end cause it will probably will be much faster to debug then waiting for an answer that may never come.
EDIT:
I found out that the size of the string won't decrease when I delete(?) the last char.
I guess it means that it always will delete the last char in the string that will be null after it was deleted once..?
EDIT:
if I delete 2chars, at the first time it will once delete 2 chars, then it will delete 1 char.
-
Maybe this should be:
Field->str.substr(0, Field->str.length() - 2);
?
Let's get first that function working well!
-
Maybe this should be:
Field->str.substr(0, Field->str.length() - 2);
?
Let's get first that function working well!
Ok, it's working, but on the first delete after each time new char was entered, as I said, it would delete the first two chars.
How do I fix the first delete? There must be a reason for this, and if we can find it we would be able to find reasonable solution.
EDIT:
Could it be a null character problem?
When I add sf::Text::Unicode to the string, does it include null character in the end of the string?
And does the null character counted by the str.length() ?
Perhaps this is the source of the problem?
Is there a way to make sure the string is NULL terminated?
-
Backspace is a valid unicode character, so it gets added to your string if you don't filter it out. So I guess that's what happened, and you always ended up adding/deleting the backspace char.
-
Backspace is a valid unicode character, so it gets added to your string if you don't filter it out. So I guess that's what happened, and you always ended up adding/deleting the backspace char.
This is heavy man... ( :lol: )
I checked if "Enter" (Return(?)) is also unicode char, I found a list on wikipedia and found "Carriage return", is it like the key.code.return?
if so I can use else if for the Text event :)
EDIT:
Thank you guys, problem fixed.
-
I checked if "Enter" (Return(?)) is also unicode char, I found a list on wikipedia and found "Carriage return", is it like the key.code.return?
Probably. You should test to be sure.