清除键盘缓冲区 [英] Clearing Keyboard Buffer
问题描述
我在VB.NET 2008中编写了一个Windows窗体应用程序。我希望
清除键盘缓冲区或至少清空所有优秀的密钥
在我的程序中的某些位置按下我的应用程序排队。
我查看了System.Console.Read,但那并没有''似乎是合适的。
我也查看了EnableWindow Lib" user32"。我遇到了一个问题
,我可以在那里禁用表单,但是无法启用表单。
代码是:
私有声明函数EnableWindow Lib" user32" (ByVal hwnd As
长,_
ByVal fenable As Long)As Long
Public Declare Function GetActiveWindow Lib" user32" ()作为
System.IntPtr
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e
As _ System .EventArgs)处理Button1.Click
Dim hWnd As IntPtr = GetActiveWindow()
调用EnableWindow(hWnd,False)
调用EnableWindow(hWnd ,真的)
结束子
我想清除键盘缓冲区的原因是我处理键盘输入是
在'Key_Up事件的形式。为了响应某些事件,我使用了SoundPlayer的PlaySync命令。当
声音播放时,我不想回复任何额外的按键
按下。目前,用户可以在播放声音的同时按键,并在声音播放完Key_Up后播放。
我尝试搜索新闻组和谷歌找不到一个好的
解决方案。也许我使用了错误的关键字。
我感谢您提供的任何建议。
谢谢!!
>
--Noah
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
推荐答案
< vb ******* @ gmail.comschrieb:
<vb*******@gmail.comschrieb:
我想要清除键盘缓冲区的原因是我在处理键盘输入时以'Key_Up事件的形式处理键盘输入。为了响应某些事件,我使用了SoundPlayer的PlaySync命令。当
声音播放时,我不想回复任何额外的按键
按下。目前,用户可以在播放声音的同时按键,并在声音播放完Key_Up后触发。
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.
\\\
Me.Enabled = False
<播放声音>
Me.Enabled = True
///
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://dotnet.mvps.org/dotnet/faqs />
\\\
Me.Enabled = False
<Play sound>
Me.Enabled = True
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
感谢您的建议。我试了一下,当表单重新启用时,Key_Up事件仍然会为每个按下的键敲响
播放声音。
Me.Enabled = False
< Play sound< Key#1 Pressed>
< Sound continue< Key#2 Pressed>
Me.Enabled = True
Key_Up用钥匙#1点火
Key_Up用钥匙#2点火
我会喜欢忽略/刷新/清除
声音播放时所做的所有按键操作。
- 否则
1月5日上午11点50分,Herfried K. Wagner [MVP] < hirf-spam-me-
h ... @ gmx.atwrote:
Thank you for the suggestion. I tried it out and when the form is
reenabled the Key_Up event still fires for each key that was pressed
while the sound played.
Me.Enabled = False
<Play sound<Key #1 Pressed>
<Sound continues<Key #2 Pressed>
Me.Enabled = True
Key_Up fires with Key #1
Key_Up fires with Key #2
I would like to ignore/flush/clear all the key presses made while the
sound plays.
--Noah
On Jan 5, 11:50 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
< vbguy2 ... @ gmail。 comschrieb:
<vbguy2...@gmail.comschrieb:
我想要清除键盘缓冲区的原因是我以Key_Up的形式处理键盘输入的
事件。为了响应某些事件,我使用了SoundPlayer的PlaySync命令。当
声音播放时,我不想回复任何额外的按键
按下。目前,用户可以在播放声音的同时按键,并在声音播放完Key_Up后触发。
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.
\\\
Me.Enabled = False
<播放声音>
Me.Enabled = True
///
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://dotnet.mvps.org/dotnet/faqs />
\\\
Me.Enabled = False
<Play sound>
Me.Enabled = True
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
您可以使用,如果没有,这里用ALT证明无论你怎么做
改变:
如果不是keys.alt = true那么
''播放声音
结束如果
希望这会有所帮助。
You may use if not, here is demonstrated with "ALT" whatever you can
change whatsoever:
if not keys.alt = true then
''play sound
end if
Hope this helps.
这篇关于清除键盘缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!