Keyboard handling of held keys

Blitz3D Forums/Blitz3D Programming/Keyboard handling of held keys

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

OK, got this sample code, should work on all keyboards around, some keys won't repeat, but they are not really useful to repeat.

Dim scancodes(256)
For i = 0 To 255
   scancodes(i) = api_OemKeyScan(i) And $ff
Next
repeat_delay = 500
repeat_rate = 100
Print "TYPE HERE:"
While Not KeyDown(1)
   timer = MilliSecs()
   ascii% = GetKey()
   If ascii > 0 Then
      ascii_repeat = ascii
      scancode% = scancodes(ascii)
      repeat_timer = timer + repeat_delay
      Write Chr$(ascii)
   EndIf
   If KeyDown(scancode) = True Then
      If timer >= repeat_timer Then
         Write Chr$(ascii_repeat)
         repeat_timer = timer + repeat_rate
      EndIf
   Else
      scancode = 0
   EndIf
Wend


Just make sure you have api_OemKeyScan in your DECLS (user32.DLL)