本文整理汇总了C#中VirtualKey.IsModifier方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualKey.IsModifier方法的具体用法?C# VirtualKey.IsModifier怎么用?C# VirtualKey.IsModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VirtualKey
的用法示例。
在下文中一共展示了VirtualKey.IsModifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckKeyCombination
private MatchKind CheckKeyCombination(KeyCombination combination, VirtualKey keyAdded, KeyCombination precedingCombination = null)
{
// A key gesture is defined by either explicit modifier keys in both combinations
// or no modifiers specified for second combination,
// but then the second combination works with either no modifiers or same modifiers as the first.
// A gesture is rejected if a combination with unrecognized non-modifier key is used.
var downState = CoreVirtualKeyStates.Down;
var ctrl = (this.window.CoreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
var alt = (this.window.CoreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
var shift = (this.window.CoreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;
if (!keyAdded.IsModifier())
{
if (combination.Contains(keyAdded))
{
foreach (var key in combination)
{
if (key == keyAdded)
{
continue;
}
if ((this.window.CoreWindow.GetKeyState(key) & downState) != downState)
{
// Missing some modifier key
return MatchKind.Mismatch;
}
}
// All the keys matched!
// Reject if found additional modifiers pressed
if (ctrl &&
(!combination.Contains(VirtualKey.Control) &&
(precedingCombination == null || !precedingCombination.Contains(VirtualKey.Control))) ||
alt &&
(!combination.Contains(VirtualKey.Menu) ||
(precedingCombination == null || !precedingCombination.Contains(VirtualKey.Menu))) ||
shift &&
(!combination.Contains(VirtualKey.Shift) ||
(precedingCombination == null || !precedingCombination.Contains(VirtualKey.Shift))))
{
return MatchKind.Mismatch;
}
return MatchKind.Match;
}
else
{
// An invalid non-modifier key was pressed
return MatchKind.Mismatch;
}
}
else
{
// Only recognizing combinations when a non-modifier key is pressed
return MatchKind.Incomplete;
}
}