如何检测当前pressed关键? [英] How to detect the currently pressed key?

查看:88
本文介绍了如何检测当前pressed关键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WinForms,你就可以知道,在任何时候,光标感谢光标类的当前位置。

同样的事情似乎没有可用的键盘。是否有可能知道,例如,Shift键是pressed?

时是绝对必要的跟踪每个键盘通知(的KeyDown和KeyUp事件)?

解决方案

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

这也将是真实的,如果<大骨节病>控制 + <大骨节病>移已关闭。如果你想单独检查是否转变为pressed,

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

如果你在一个类继承控制(如表),可以删除控制。

In WinForms, you can know, at any time, the current position of the cursor thanks to the Cursor class.

The same thing doesn't seem to be available for the keyboard. Is it possible to know if, for example, the Shift key is pressed?

Is it absolutely necessary to track down every keyboard notification (KeyDown and KeyUp events)?

解决方案

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

This will also be true if Ctrl+Shift is down. If you want to check whether Shift alone is pressed,

if (Control.ModifierKeys == Keys.Shift)

If you're in a class that inherits Control (such as a form), you can remove the Control.

这篇关于如何检测当前pressed关键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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