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); } }
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; } }