V
vbguy2008
Hi,
I am coding a Windows Form Application in VB.NET 2008. I would like
to clear the keyboard buffer or at least empty all outstanding key
presses queued up for my application at certain points in my program.
I looked at System.Console.Read, but that doesn't seems appropriate.
I also looked into EnableWindow Lib "user32". I ran into a problem
where I could disable the form, but was unable to enable the form.
The code is:
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As
Long, _
ByVal fenable As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As
System.IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As _ System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = GetActiveWindow()
Call EnableWindow(hWnd, False)
Call EnableWindow(hWnd, True)
End Sub
The reason that I want to clear the keyboard buffer is that I am
handling keyboard input in the form's Key_Up event. In response to
certain events, I use the SoundPlayer's PlaySync command. While the
sound is playing, I don't want to respond to any additional key
presses. Currently, the user can press keys while the sound is
playing and after the sound is done playing Key_Up fires.
I tried searching the newsgroups and Google and could not find a good
solution. Perhaps I am using the wrong keywords.
I appreciate any advice you can offer.
Thanks!!
--Noah
I am coding a Windows Form Application in VB.NET 2008. I would like
to clear the keyboard buffer or at least empty all outstanding key
presses queued up for my application at certain points in my program.
I looked at System.Console.Read, but that doesn't seems appropriate.
I also looked into EnableWindow Lib "user32". I ran into a problem
where I could disable the form, but was unable to enable the form.
The code is:
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As
Long, _
ByVal fenable As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As
System.IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As _ System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = GetActiveWindow()
Call EnableWindow(hWnd, False)
Call EnableWindow(hWnd, True)
End Sub
The reason that I want to clear the keyboard buffer is that I am
handling keyboard input in the form's Key_Up event. In response to
certain events, I use the SoundPlayer's PlaySync command. While the
sound is playing, I don't want to respond to any additional key
presses. Currently, the user can press keys while the sound is
playing and after the sound is done playing Key_Up fires.
I tried searching the newsgroups and Google and could not find a good
solution. Perhaps I am using the wrong keywords.
I appreciate any advice you can offer.
Thanks!!
--Noah