mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Set up unified Modifier key checker
This commit is contained in:
@@ -88,18 +88,18 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
}
|
||||
|
||||
// Count current modifiers
|
||||
int modifierCount = _currentlyPressedKeys.Count(k => _activeTarget.IsModifierKey(k));
|
||||
int modifierCount = _currentlyPressedKeys.Count(k => RemappingHelper.IsModifierKey(k));
|
||||
|
||||
// If adding this key would exceed the limits (4 modifiers + 1 action key), don't add it and show notification
|
||||
if ((_activeTarget.IsModifierKey(virtualKey) && modifierCount >= 4) ||
|
||||
(!_activeTarget.IsModifierKey(virtualKey) && _currentlyPressedKeys.Count >= 5))
|
||||
if ((RemappingHelper.IsModifierKey(virtualKey) && modifierCount >= 4) ||
|
||||
(!RemappingHelper.IsModifierKey(virtualKey) && _currentlyPressedKeys.Count >= 5))
|
||||
{
|
||||
_activeTarget.OnInputLimitReached();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this is a different variant of a modifier key already pressed
|
||||
if (_activeTarget.IsModifierKey(virtualKey))
|
||||
if (RemappingHelper.IsModifierKey(virtualKey))
|
||||
{
|
||||
// Remove existing variant of this modifier key if a new one is pressed
|
||||
// This is to ensure that only one variant of a modifier key is displayed at a time
|
||||
@@ -151,7 +151,7 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_activeTarget.IsModifierKey(key))
|
||||
if (RemappingHelper.IsModifierKey(key))
|
||||
{
|
||||
if (!modifierKeys.Contains(key))
|
||||
{
|
||||
@@ -234,8 +234,6 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
|
||||
void ClearKeys();
|
||||
|
||||
bool IsModifierKey(VirtualKey key);
|
||||
|
||||
void OnInputLimitReached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using KeyboardManagerEditorUI.Interop;
|
||||
using ManagedCommon;
|
||||
using Windows.System;
|
||||
|
||||
namespace KeyboardManagerEditorUI.Helpers
|
||||
{
|
||||
@@ -124,5 +125,20 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsModifierKey(VirtualKey key)
|
||||
{
|
||||
return key == VirtualKey.Control
|
||||
|| key == VirtualKey.LeftControl
|
||||
|| key == VirtualKey.RightControl
|
||||
|| key == VirtualKey.Menu
|
||||
|| key == VirtualKey.LeftMenu
|
||||
|| key == VirtualKey.RightMenu
|
||||
|| key == VirtualKey.Shift
|
||||
|| key == VirtualKey.LeftShift
|
||||
|| key == VirtualKey.RightShift
|
||||
|| key == VirtualKey.LeftWindows
|
||||
|| key == VirtualKey.RightWindows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,21 +168,6 @@ namespace KeyboardManagerEditorUI.Styles
|
||||
KeyboardHookHelper.Instance.CleanupHook();
|
||||
}
|
||||
|
||||
public bool IsModifierKey(VirtualKey key)
|
||||
{
|
||||
return key == VirtualKey.Control
|
||||
|| key == VirtualKey.LeftControl
|
||||
|| key == VirtualKey.RightControl
|
||||
|| key == VirtualKey.Menu
|
||||
|| key == VirtualKey.LeftMenu
|
||||
|| key == VirtualKey.RightMenu
|
||||
|| key == VirtualKey.Shift
|
||||
|| key == VirtualKey.LeftShift
|
||||
|| key == VirtualKey.RightShift
|
||||
|| key == VirtualKey.LeftWindows
|
||||
|| key == VirtualKey.RightWindows;
|
||||
}
|
||||
|
||||
public void SetRemappedKeys(List<string> keys)
|
||||
{
|
||||
_remappedKeys.Clear();
|
||||
|
||||
@@ -194,16 +194,6 @@ namespace KeyboardManagerEditorUI.Styles
|
||||
UpdateAllAppsCheckBoxState();
|
||||
}
|
||||
|
||||
public bool IsModifierKey(VirtualKey key)
|
||||
{
|
||||
return key == VirtualKey.Control || key == VirtualKey.Menu ||
|
||||
key == VirtualKey.Shift || key == VirtualKey.LeftWindows ||
|
||||
key == VirtualKey.RightWindows || key == VirtualKey.LeftControl ||
|
||||
key == VirtualKey.RightControl || key == VirtualKey.LeftMenu ||
|
||||
key == VirtualKey.RightMenu || key == VirtualKey.LeftShift ||
|
||||
key == VirtualKey.RightShift;
|
||||
}
|
||||
|
||||
public List<string> GetShortcutKeys()
|
||||
{
|
||||
List<string> keys = new List<string>();
|
||||
|
||||
Reference in New Issue
Block a user