Change behavior on Edit Keyboard screen to be physical keys (#2666)

* Commented out ToggleToMod and AppSpecific function calls

* Added logic to make sure key remaps don't occur on Edit Keyboard Window

* Changed behavior such that remappings only apply after window is closed
This commit is contained in:
Arjun Balgovind
2020-05-04 15:49:37 -07:00
committed by GitHub
parent 855f3d74fe
commit c4f884f104
8 changed files with 82 additions and 28 deletions

View File

@@ -20,18 +20,18 @@ KeyboardManagerState::~KeyboardManagerState()
}
}
// Function to check the if the UI state matches the argument state. For states with activated windows it also checks if the window is in focus.
// Function to check the if the UI state matches the argument state. For states with detect windows it also checks if the window is in focus.
bool KeyboardManagerState::CheckUIState(KeyboardManagerUIState state)
{
std::lock_guard<std::mutex> lock(uiState_mutex);
if (uiState == state)
{
std::unique_lock<std::mutex> lock(currentUIWindow_mutex);
if (uiState == KeyboardManagerUIState::Deactivated)
if (uiState == KeyboardManagerUIState::Deactivated || uiState == KeyboardManagerUIState::EditKeyboardWindowActivated || uiState == KeyboardManagerUIState::EditShortcutsWindowActivated)
{
return true;
}
// If the UI state is activated then we also have to ensure that the UI window is in focus.
// If the UI state is a detect window then we also have to ensure that the UI window is in focus.
// GetForegroundWindow can be used here since we only need to check the main parent window and not the sub windows within the content dialog. Using GUIThreadInfo will give more specific sub-windows within the XAML window which is not needed.
else if (currentUIWindow == GetForegroundWindow())
{
@@ -254,14 +254,14 @@ void KeyboardManagerState::ResetDetectedShortcutKey(DWORD key)
}
// Function which can be used in HandleKeyboardHookEvent before the single key remap event to use the UI and suppress events while the remap window is active.
bool KeyboardManagerState::DetectSingleRemapKeyUIBackend(LowlevelKeyboardEvent* data)
KeyboardManagerHelper::KeyboardHookDecision KeyboardManagerState::DetectSingleRemapKeyUIBackend(LowlevelKeyboardEvent* data)
{
// Check if the detect key UI window has been activated
if (CheckUIState(KeyboardManagerUIState::DetectSingleKeyRemapWindowActivated))
{
if (HandleKeyDelayEvent(data))
{
return true;
return KeyboardManagerHelper::KeyboardHookDecision::Suppress;
}
// detect the key if it is pressed down
if (data->wParam == WM_KEYDOWN || data->wParam == WM_SYSKEYDOWN)
@@ -270,21 +270,27 @@ bool KeyboardManagerState::DetectSingleRemapKeyUIBackend(LowlevelKeyboardEvent*
}
// Suppress the keyboard event
return true;
return KeyboardManagerHelper::KeyboardHookDecision::Suppress;
}
return false;
// If the settings window is up, remappings should not be applied, but we should not suppress events in the hook
else if (CheckUIState(KeyboardManagerUIState::EditKeyboardWindowActivated))
{
return KeyboardManagerHelper::KeyboardHookDecision::SkipHook;
}
return KeyboardManagerHelper::KeyboardHookDecision::ContinueExec;
}
// Function which can be used in HandleKeyboardHookEvent before the os level shortcut remap event to use the UI and suppress events while the remap window is active.
bool KeyboardManagerState::DetectShortcutUIBackend(LowlevelKeyboardEvent* data)
KeyboardManagerHelper::KeyboardHookDecision KeyboardManagerState::DetectShortcutUIBackend(LowlevelKeyboardEvent* data)
{
// Check if the detect shortcut UI window has been activated
if (CheckUIState(KeyboardManagerUIState::DetectShortcutWindowActivated))
{
if (HandleKeyDelayEvent(data))
{
return true;
return KeyboardManagerHelper::KeyboardHookDecision::Suppress;
}
// Add the key if it is pressed down
@@ -299,7 +305,7 @@ bool KeyboardManagerState::DetectShortcutUIBackend(LowlevelKeyboardEvent* data)
}
// Suppress the keyboard event
return true;
return KeyboardManagerHelper::KeyboardHookDecision::Suppress;
}
// If the detect shortcut UI window is not activated, then clear the shortcut buffer if it isn't empty
@@ -312,7 +318,13 @@ bool KeyboardManagerState::DetectShortcutUIBackend(LowlevelKeyboardEvent* data)
}
}
return false;
// If the settings window is up, shortcut remappings should not be applied, but we should not suppress events in the hook
if (CheckUIState(KeyboardManagerUIState::EditShortcutsWindowActivated))
{
return KeyboardManagerHelper::KeyboardHookDecision::SkipHook;
}
return KeyboardManagerHelper::KeyboardHookDecision::ContinueExec;
}
void KeyboardManagerState::RegisterKeyDelay(