C#键枚举困惑:Keys.Alt或Keys.RButton | Keys.ShiftKey | Keys.Alt [英] C# Keys Enumeration Confused: Keys.Alt or Keys.RButton | Keys.ShiftKey | Keys.Alt
问题描述
我是想测试Alt键是按下
I was trying to test whether the Alt key was pressed.
我有类似的检查:
private void ProcessCmdKey(Keys keyData)
{
if (keyData == Keys.Alt)
{
System.Console.WriteLine ("Alt Key Pressed");
}
}
反正不用说,当我breakpointed当我一压Alt键调试器告诉我按下的键竟是Keys.RButton | Keys.ShiftKey | Keys.Alt
Anyways needless to say when I breakpointed when I had pressed the Alt key the debugger told me the key that was pressed was actually Keys.RButton | Keys.ShiftKey | Keys.Alt
任何人都可以阐明正在发生的事情或者指向我可以解释的文章一些轻?
Can anyone shed some light on what is going on or perhaps point me to an article that can explain?
由于
FZ
Thanks FZ
编辑:
我还是有点失落,为什么ENUM就必须有其他位值设置和不是单纯的Alt键?据我所知,枚举可以包括1个多国家的国旗attrivbute,但我不知道它为什么如果所有我按下Alt键了?
I am still a bit lost as to why the ENUM would have have other bit values set and not simply the Alt key? I understand that the enum can include more than 1 state with the flags attrivbute but I am not sure why it does if all I pressed was Alt?
推荐答案
如果你想测试是否替代
是部分的按下的键,可以进行按位测试;
If you want to test whether Alt
is part of the pressed keys, you can perform a bitwise test;
if((keyData & Keys.Alt) == Keys.Alt) {...}
这篇关于C#键枚举困惑:Keys.Alt或Keys.RButton | Keys.ShiftKey | Keys.Alt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!