GetKey() question

BlitzMax Forums/BlitzMax Programming/GetKey() question

Russell(Posted 2005) [#1]
Ok, GetKey() and WaitKey() return the scan code, as opposed to the ascii code, of the pressed key. Makes sense. But how come the value of the key is left in the queue, even if the value is placed in a variable (a = GetKey()). Shouldn't the queue be cleared after a value is 'popped' from it?

I know I can use FlushKeys(), but I was just wondering why this was done this way.

WaitChar(), I know, uses GetChar() to see if there are any keys in the buffer and this makes sense to me. But the other two, WaitKey() and KeyDown(<key>) were, I thought, 'immediate mode' commands that didn't use the buffer at all but simply tested the keyboard at that very moment, etc.

Am I making sense?

Thanks,
Russell

p.s. I think it should also be pointed out that not all of these input commands work as expected in a non-graphics mode (console).


tonyg(Posted 2005) [#2]
From HERE
"Whether or not WaitKey should 'flush' the hit key is a matter of opinion. In my opinion, it should, as this keeps things synchronous and removes the need for FlushKeys all over the place." from Mark.
The waitkey loop still occurs so it appears to flush the key. Have you got some code to show it *not* flushing the keyhit?


Russell(Posted 2005) [#3]
Oops, I meant KeyDown(), not GetKey().
Graphics(640,480,0)
a = WaitKey()
Delay(3000)
Print GetChar()

(The delay is there so that the GetChar() doesn't read the key I may still be pressing).
This prints the value of whatever key you hit instead of zero.

Russell