检测按下Shift键,而不在Windows窗体中使用的事件? [英] Detect Shift key is pressed without using events in Windows Forms?

查看:125
本文介绍了检测按下Shift键,而不在Windows窗体中使用的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够检测到换档键被保持,但我不希望使用的事件或全局变量来确定。有没有在C#中,可以让你问目前什么压,而不是使用事件密钥的API?


解决方案

  IF((Control.ModifierKeys&安培;!Keys.Shift)= 0)

这也将是真正如果另一个修改键也下来了(比如,按Ctrl + Shift)。如果你想单独检查移位是否在没有任何其他修饰符按下,用



 如果(Control.ModifierKeys == Keys.Shift )

请注意,即使这将是真正如果另一个非改性剂是(例如,Shift + A)。如果你想检查是否移位和的只有的按下Shift键,你必须使用一个API调用。






如果您在继承控制(如表格)一类的时候,你可以删除控制预选赛。 (静态属性不需要继承类预选赛)


I need to be able to detect that the shift key is being held, but I don't want to use events or global variables to determine that. Is there an API in C# that lets you ask what keys are currently pressed instead of using the event?

解决方案

if ((Control.ModifierKeys & Keys.Shift) != 0)

This will also be true if another modifier key is also down (eg, Ctrl+Shift). If you want to check whether Shift alone is pressed without any other modifiers, use

if (Control.ModifierKeys == Keys.Shift)

Note that even this will be true if another non-modifier is down (Eg, Shift+A). If you want to check whether Shift and only Shift is pressed, you'll have to use an API call.


If you're in a class that inherits Control (such as a form), you can remove the Control qualifier. (static properties don't need qualifiers in inherited classes)

这篇关于检测按下Shift键,而不在Windows窗体中使用的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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