I am trapping a KeyDown
event and I need to be able to check whether the current keys pressed down are : Ctrl + Shift + M ?
我知道我需要使用e.KeyData
来自KeyEventArgs
, the Keys
枚举以及带有枚举标志和位的东西,但我不确定如何检查组合。
您需要使用修饰符 http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.modifiers.aspxKeyEventArgs 类的属性。
就像是:
//asumming e is of type KeyEventArgs (such as it is
// on a KeyDown event handler
// ..
bool ctrlShiftM; //will be true if the combination Ctrl + Shift + M is pressed, false otherwise
ctrlShiftM = ((e.KeyCode == Keys.M) && // test for M pressed
((e.Modifiers & Keys.Shift) != 0) && // test for Shift modifier
((e.Modifiers & Keys.Control) != 0)); // test for Ctrl modifier
if (ctrlShiftM == true)
{
Console.WriteLine("[Ctrl] + [Shift] + M was pressed");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)