How to clear/set key in keyboard buffer ?

DOS specific questions.
Post Reply
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

How to clear/set key in keyboard buffer ?

Post by Cpcdos »

Hello everyone!

I would to know how to
  • Set a ascii character or number in keyboard buffer ?
  • Clear my keyboard buffer ?
    I use inkey for get a ascii character. When I type very fast on my keyboard, inkey accumulates and returns more character that I've previously typed (speedily)
    And when I type ENTER, this buffer is cleared

    I tested to clear with

    Code: Select all

    While Inkey <> "": Wend
    but this not work.
Best regards
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: How to clear/set key in keyboard buffer ?

Post by grindstone »

Hello Cpcdos!

I doubt that any human can type faster than a computer processes the input. It's a strange behaviour. Maybe there's something wrong with your keyboard (contact bounce)?

Some time ago I wrote a sub that sends a keystroke simulation to the foreground window. Maybe it can help you.

Code: Select all

#Include Once "windows.bi"

Sub KeySim(key As String = "")
	Dim As IINPUT ip
	Dim As String ut
	Dim As UByte ta
	
	ta = Asc(UCase(Right(key,1))) 'key as capital
	If Len(key) > 1 Then
		ut = LCase(Left(key,InStr(key, Any " +") - 1)) 'isolate function key
	Else
		ut = "" 'no function key
	EndIf
	
	ip.itype = INPUT_KEYBOARD
	With ip.ki
		.wScan = 0
		.dwFlags = 0
		
		If ut <> "" Then
			Select Case ut 'press function key
				Case "shift"
					.wVk = VK_SHIFT
				Case "alt"
					.wVk = VK_MENU
				Case "altgr"
					.wVk = VK_RMENU
				Case "ctrl"
					.wVk = VK_CONTROL
			End Select
			SendInput(1,Cast(LPINPUT,@ip),SizeOf(ip))
		EndIf
				
		.wVk = ta
		SendInput(1,Cast(LPINPUT,@ip),SizeOf(ip))	'press key
		
		.dwFlags = KEYEVENTF_KEYUP
		SendInput(1,Cast(LPINPUT,@ip),SizeOf(ip))	'release key
		
		If ut <> "" Then
			Select Case ut 'release function key
				Case "shift"
					.wVk = VK_SHIFT
				Case "alt"
					.wVk = VK_MENU
				Case "altgr"
					.wVk = VK_RMENU
				Case "ctrl"
					.wVk = VK_CONTROL
			End Select
			SendInput(1,Cast(LPINPUT,@ip),SizeOf(ip))
		EndIf
				
	End With

End Sub
How the sub is to be used:

Code: Select all

...
SetForegroundWindow(hWndAudacity)
Sleep 100    			
KeySim("alt+d") 'open file menu
KeySim("i") 'import
KeySim("a") 'audio
...
Regards
grindstone
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: How to clear/set key in keyboard buffer ?

Post by Cpcdos »

Hello grindstone

Thank you for your reply ! :)

My buffer problem was resolved, it is my threading management that is bad (in another function)

Thank you
Post Reply