C#:从 KeyEventArgs 获取按下的正确按键 关键数据
我正在捕获 KeyDown
事件,我需要能够检查当前按下的键是否为: Ctrl + Shift + M?
我知道我需要使用 KeyEventArgs
中的 e.KeyData
、Keys
枚举以及带有枚举标志和位的内容,但我不是确定如何检查组合。
I am trapping a KeyDown
event and I need to be able to check whether the current keys pressed down are : Ctrl + Shift + M ?
I know I need to use the e.KeyData
from the KeyEventArgs
, the Keys
enum and something with Enum Flags and bits but I'm not sure on how to check for the combination.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用修饰符 KeyEventArgs 类的属性。
就像是:
You need to use the Modifiers property of the KeyEventArgs class.
Something like:
我认为使用它最简单:
if(e.KeyData == (Keys.Control | Keys.G))
I think its easiest to use this:
if(e.KeyData == (Keys.Control | Keys.G))
您可以使用类似于以下的技术进行检查:
这与正常的键检查相结合将为您提供所需的答案。
You can check using a technique similar to the following:
This in combination with the normal key checks will give you the answer you seek.