Keyhit bug? I'm confused.

BlitzMax Forums/BlitzMax Programming/Keyhit bug? I'm confused.

sswift(Posted 2006) [#1]
If KeyHit(KEY_BACKSPACE) Then DebugLog("backspace")						
'							If KeyHit(KEY_BACKSPACE)
							
'								If Len(SaveGames._Name$[SaveGames.Active]) > 1
'									SaveGames._Name$[SaveGames.Active] = Mid$(SaveGames._Name$[SaveGames.Active], 1, Len(SaveGames._Name$[SaveGames.Active])-1)
'									UpdatePlayerSlots()
'									Return	
'								EndIf
								
'							EndIf



If I have the first IF statement uncommented, and I press backspace, each time I press it the debuglog is printed to once.

If I have the second IF statement uncommented, and I press backspace, the code in the second IF is triggered CONTINUOUSLY, at a slowish pace as if I'm pressing it every half second or so.

[edit]
Well, it turns out that's not quite true. A debug reveals the letters are not being deleted because of this code. I think it is my cursor blink code which is doing it somehow.
[/code]


fredborg(Posted 2006) [#2]
Graphics 640,480,0,0
While Not KeyHit(KEY_ESCAPE)
If KeyHit(KEY_BACKSPACE) Then Print("backspace")						
If KeyHit(KEY_BACKSPACE)
	Print "Second Backspace"
EndIf
Delay 1
Wend
This seems to work fine... maybe you are doing something in between which is not correct?


Dreamora(Posted 2006) [#3]
This is no bug.

KeyHit counts the number of keyhits since the last call of keyhit.

You would need to be the fastest person on earth to get it show both.

There are 2 possibilities:

1. use keyDown
2. Save the value of keyhit to a variable and use that variable within this mainloop run.


sswift(Posted 2006) [#4]
Yeah I found the bug. Just a mistake on my part.

It was the once every half second or so that tipped me off to the real problem. The cursor blink code works by adding an underscore to the end of the string and changing that to a space every 250ms. But when I deleted a character from the end of the string, the cursor blink code couldn't figure out whether to put an _ or a space there, and it ended up just deleting the character. And it continued to do so as the rest of the string didn't contain a space or an underscore to get it back to normal.

So I just had to delete the SECOND to last character in the string when backspace is pressed, and that solved it.