什么是Keys.Control /移位和Keys.ControlKey / Shift键之间的精确区别是什么? [英] What's the exact difference between Keys.Control/Shift and Keys.ControlKey/ShiftKey?

查看:2270
本文介绍了什么是Keys.Control /移位和Keys.ControlKey / Shift键之间的精确区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Keys.Control之间的确切差异,Keys.ControlKey / Keys.Shift和Keys.ShiftKey System.Windows.Forms中?

What's the exact difference between Keys.Control and Keys.ControlKey/Keys.Shift and Keys.ShiftKey in System.Windows.Forms?

我GOOGLE了它,但没有具体的来了,它似乎并没有被记录在MSDN上无论是。

I've googled it but nothing specific came up, and it doesn't seem to be documented on MSDN either.

就个人而言,我总是用Keys.Control / Keys.Shift,因为它工作正常。

Personally, I always use Keys.Control/Keys.Shift, because it works fine.

编辑:阅读KreepN的回答后,我想,如果你从来没有使用控制/班,为什么他们的框架?

After reading KreepN's answer, I thought if you never have to use Control/Shift, why are they in the framework?

我的意思是,他们甚至没有物理按键,所以我不能看到微软之所以决定创建它们。

I mean, they aren't even the physical keys, so I can't see the reason why Microsoft decided to create them.

在什么情况下它是更好地使用控制/移?

Are there circumstances where it's better to use Control/Shift?

推荐答案

ControlKey和Shift键(和菜单 - 你会以为会是 名为Alt键)重新present物理密钥本身。换言之,他们 是实际的的键,可以在一个KeyEventArgs的密钥code属性中找到 对象。

ControlKey and ShiftKey (and Menu--which you would assume would have been named AltKey) represent the physical keys themselves. In other words, they are "actual" keys and can be found in the KeyCode property of a KeyEventArgs object.

控制,Shift和Alt键,而另一方面,绝不会出现在关键code 属性,但是它们的值可以在KEYDATA属性中找到。看起来 你从来没有真正需要使用这些常量,因为框架 已经通过Alt键,控制拉出来为你和Shift属性 在KeyEventArgs反对,但你可以用它们来测试对KEYDATA 属性,如果你真的想。

Control, Shift, and Alt, on the other hand, will never appear in the KeyCode property, but their values can be found in the KeyData property. It seems you never actually NEED to use these constants, because the framework already pulls them out for you via the Alt, Control, and Shift properties of the KeyEventArgs object, but you CAN use them to test against the KeyData property if you really want to.

<一个href="http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms/2008-04/msg00127.html"相对=nofollow>来源与范例。

编辑为您编辑:

看的时候,一个关键是pressed所返回的值:

Look at the values that are returned when the "a" key is pressed:

A(未移位)/ 41/41

a (unshifted) / 41 / 41

A(Shift + A)/10041分之41

A (Shift+a) / 41 / 10041

CTRL + A /二万零四十一分之四十一

Ctrl+a / 41 / 20041

在这种情况下,关键code是= 41的所有修改。你可以使用这个在code,如果你关心的是主键pressed,在这种情况下,A。

The "KeyCode" in this case is = 41 for all modifiers. You could use this in code if all you cared about was the primary button pressed, in this case "a".

如果你想有一个基于不同的功能,如果一个修改是pressed,你需要得到更具体,引用了KEYDATA字段并查找表示一定修改的#。在这种情况下,100为移位和200为在外地的开始控制

If you wanted to have different functionality based on if a modifier was pressed you would need to get more specific and reference the "KeyData" field and look for the # that denoted a certain modifier. In this case "100" for shift and "200" for control at the beginning of the field.

这并不是说你不能只检查了41在KEYDATA场的结束,但我从来不抱怨的便利。

That's not to say you couldn't just check for the "41" at the end of the KeyData field, but I've never been one to complain about convenience.

这将是安全地说,差异化您正在寻找它们之间在你的第一个问题是,它们引用不同的属性字段。

It would be safe to say that the "difference" you are looking for between them in your first question is that they reference different property fields.

编辑了解更多的相关性: 在功能键的值结合键值直接相关的快捷方式枚举成员。例如: Shortcut.CtrlF8(0x20077)是一样的Keys.Control | Keys.F8(地址0x20000 | 0x77)

Edit for additional relevance: The key modifier values combined with the key value directly correlate to the Shortcut enumeration members. For example: Shortcut.CtrlF8 ( 0x20077 ) is the same as Keys.Control | Keys.F8 ( 0x20000 | 0x77 )

这可以在与菜单项所定义的快捷方式的属性打交道是有用的。

This can be useful when dealing with the defined Shortcut properties of menu items.

这篇关于什么是Keys.Control /移位和Keys.ControlKey / Shift键之间的精确区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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