在.NET中的键盘事件 [英] keyboard events in .NET

查看:166
本文介绍了在.NET中的键盘事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关键事件被当松开按键触发。这适用于普通键像A,B等,但真正的,按住方向键或退出键produses不同的结果。
相反发射的一个关键事件,关键是释放的时候,它就会key down事件后不久就被解雇了。因此,按住一个箭头键等于按下并释放键多次非常快。
任何的解释和解决,以确定何时该键实际上是释放?

The key up event gets triggered when a key is released. This holds true for normal keys like a, b etc. However, holding down the arrow key or escape key produses different results. Instead of firing a key up event when the key is released, it gets fired soon after the key down event. So, holding down a arrow key becomes equal to pressing and releasing the key many times very fast. Any explaination and work around to determine when the key is actually released?

推荐答案

KeyUp事件实际上不是解雇(所有密钥不只是方向键等),直到你松开按键,有许多只是重复的KeyDown事件。至少,这是在我看来,从一些测试代码的方式。

The KeyUp event isn't actually fired (for all keys not just arrow keys etc.) until you release the key, there are just many repeated KeyDown events. At least, that's the way it looks to me from some test code.

我的解决方法是禁用在KeyDown处理程序使用

My workaround is to disable the KeyDown handler after a KeyDown event is detected using

RemoveHandler Me.KeyDown, AddressOf Form1_KeyDown

,然后重新启用时,KEYUP事件被解雇了。

and then re-enabling when the KeyUP event is fired.

AddHandler Me.KeyDown, AddressOf Form1_KeyDown

当然,如果你想同时处理多个按键,那么这将无法工作。你必须保存在问题的关键是否已经下降,而忽略各自的KeyDown事件。

Of course if you want to handle simultaneous multiple key presses then this won't work. You'll have to store whether or not the Key in question is already down and ignore the respective KeyDown event.

这篇关于在.NET中的键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆