Simulation GetKey() without flush?

Blitz3D Forums/Blitz3D Programming/Simulation GetKey() without flush?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I have done a working keyrepeat function using GetKey in combo with KeyDown, as jfk EO-11110 suggested.
It should work with all languages and keymaps/keyboards since it uses GetKey() to get the ascii code.

And here it is for those of you that want it.
Of course it can be improved. One thing is that it ignores shift and altgr presses for the repeat. These could be easily added if the need arises.

And if you only need keyrepeats for scancodes, just use the KeyRepeats() function and skip the stuff in KeyChecks() except the print lines at the bottom. It´s pretty generic.

Thanks guys for your help!

-------------------
Global glob_keypressed=False
Global glob_keypressed_timer=0
Global glob_keycheck_ok=True
Global glob_keyrepeat_start=False

Global glob_input_ascii
Global glob_input_scan

;-- Main loop --
Repeat

	KeyChecks()
	KeyRepeats()

Until KeyHit(1)
End
;--
Function KeyChecks()

	Local input_ascii_gk
	Local scan

	If glob_keypressed=False
		input_ascii_gk=GetKey()
		If input_ascii_gk>=32 And input_ascii_gk<>127	;allow ascii above 31, except 127(Del)
			glob_keypressed=True
			glob_input_ascii=input_ascii_gk		
			For scan=0 To 255
				If KeyDown(scan)			
					If scan<>42 Or scan<>54 Or scan<>184	;ignore RShift, LShift, AltGr
						glob_input_scan=scan
						Exit
					End If
				End If
			Next
		Else
			glob_input_ascii=0
		End If
	Else	
		For scan=0 To 255
			If KeyDown(scan)		
				input_scan=scan
				Exit
			End If
		Next
		If input_scan<>glob_input_scan
			glob_keypressed=False
		End If
	End If

	If glob_keypressed=True And glob_keycheck_ok=True
		;-- Do your printing here --
		Print Chr$(glob_input_ascii)
	End If

End Function
;--
Function KeyRepeats()
	If glob_keypressed=True
		If glob_keypressed_timer=0
			glob_keypressed_timer=MilliSecs()
			glob_keycheck_ok=False
		Else
			If (MilliSecs()-glob_keypressed_timer)>600 And glob_keyrepeat_start=False
				glob_keypressed_timer=0
				glob_keycheck_ok=True
				glob_keyrepeat_start=True
			Else If (MilliSecs()-glob_keypressed_timer)>40 And glob_keyrepeat_start=True
				glob_keypressed_timer=0
				glob_keycheck_ok=True
			End If
		End If
	Else
		glob_keypressed_timer=0
		glob_keycheck_ok=True
		glob_keyrepeat_start=False
	End If
End Function