FlushKeyRange()

BlitzMax Forums/BlitzMax Module Tweaks/FlushKeyRange()

Perturbatio(Posted 2005) [#1]
inspired by this thread, I decided to make this function.
It could probably be implemented better, but it's a start.

in brl.mod\system.mod\system.<OS>.c (or .m for mac) add:
void bbSystemFlushKeyRange(int lowRange, int highRange){
	int loopVar = 0;
	if (lowRange > highRange) { return;}
	if (lowRange<0 || highRange>256){return;}
	for (loopVar = lowRange; loopVar<= highRange; loopVar++){
		key_hit[loopVar] = 0;
		key_down[loopVar] = 0;
	}
	char_put=char_get=0;
}


in driver.bmx add:
	Method FlushKeyRange(lowRange, highRange) Abstract
below flushmem



in system.bmx add:
Rem
bbdoc: Flush the keyboard buffers from lowRange to highRange
End Rem
Function FlushKeyRange(lowRange, highRange)
	If auto_poll PollSystem
	Driver.FlushKeyRange(lowRange, highRange)
End Function


Only tested on win32, but the flushkeys function is exactly the same for each OS so it shouldn't be an issue.

Usage: FlushKeyRange(lowRange, highRange)

example:
'flushmouse only
FlushKeyRange(KEY_MOUSELEFT, KEY_MOUSEMIDDLE)

another example:
Graphics 640,480,0,0

While Not KeyDown(KEY_ESCAPE)
Cls
	If KeyDown(KEY_MOUSELEFT) Then Print RequestDir("Choose a directory", "c:\")
	FlushKeyRange(KEY_MOUSELEFT, KEY_MOUSELEFT)
	If KeyDown(KEY_A) Then DrawText("A Pressed", 10, 10)
Flip
Wend