diff --git a/src/common/common.vcxproj b/src/common/common.vcxproj index 230cb8dd7f..29425be882 100644 --- a/src/common/common.vcxproj +++ b/src/common/common.vcxproj @@ -124,6 +124,7 @@ + diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters index c58c72019d..67cbad8a7b 100644 --- a/src/common/common.vcxproj.filters +++ b/src/common/common.vcxproj.filters @@ -99,6 +99,9 @@ Header Files + + Header Files + Header Files diff --git a/src/common/shared_constants.h b/src/common/shared_constants.h new file mode 100644 index 0000000000..e719c11add --- /dev/null +++ b/src/common/shared_constants.h @@ -0,0 +1,8 @@ +#pragma once +#include "common.h" + +namespace CommonSharedConstants +{ + // Flag that can be set on an input event so that it is ignored by Keyboard Manager + const ULONG_PTR KEYBOARDMANAGER_INJECTED_FLAG = 0x1; +} \ No newline at end of file diff --git a/src/modules/keyboardmanager/dll/dllmain.cpp b/src/modules/keyboardmanager/dll/dllmain.cpp index ce5edd48bd..fe5da44ca0 100644 --- a/src/modules/keyboardmanager/dll/dllmain.cpp +++ b/src/modules/keyboardmanager/dll/dllmain.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "trace.h" #include "resource.h" #include @@ -43,7 +44,6 @@ private: const std::wstring app_name = GET_RESOURCE_STRING(IDS_KEYBOARDMANAGER); // Flags used for distinguishing key events sent by Keyboard Manager - static const ULONG_PTR KEYBOARDMANAGER_INJECTED_FLAG = 0x1; static const ULONG_PTR KEYBOARDMANAGER_SINGLEKEY_FLAG = 0x11; static const ULONG_PTR KEYBOARDMANAGER_SHORTCUT_FLAG = 0x101; @@ -407,7 +407,7 @@ public: intptr_t HandleSingleKeyRemapEvent(LowlevelKeyboardEvent* data) noexcept { // Check if the key event was generated by KeyboardManager to avoid remapping events generated by us. - if (!(data->lParam->dwExtraInfo & KEYBOARDMANAGER_INJECTED_FLAG)) + if (!(data->lParam->dwExtraInfo & CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG)) { // The mutex should be unlocked before SendInput is called to avoid re-entry into the same mutex. More details can be found at https://github.com/microsoft/PowerToys/pull/1789#issuecomment-607555837 std::unique_lock lock(keyboardManagerState.singleKeyReMap_mutex); @@ -446,7 +446,7 @@ public: intptr_t HandleSingleKeyToggleToModEvent(LowlevelKeyboardEvent* data) noexcept { // Check if the key event was generated by KeyboardManager to avoid remapping events generated by us. - if (!(data->lParam->dwExtraInfo & KEYBOARDMANAGER_INJECTED_FLAG)) + if (!(data->lParam->dwExtraInfo & CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG)) { // The mutex should be unlocked before SendInput is called to avoid re-entry into the same mutex. More details can be found at https://github.com/microsoft/PowerToys/pull/1789#issuecomment-607555837 std::unique_lock lock(keyboardManagerState.singleKeyToggleToMod_mutex); diff --git a/src/modules/shortcut_guide/target_state.cpp b/src/modules/shortcut_guide/target_state.cpp index 18835e39b0..16a2357d57 100644 --- a/src/modules/shortcut_guide/target_state.cpp +++ b/src/modules/shortcut_guide/target_state.cpp @@ -2,6 +2,7 @@ #include "target_state.h" #include "common/start_visible.h" #include "keyboard_state.h" +#include "common/shared_constants.h" TargetState::TargetState(int ms_delay) : delay(std::chrono::milliseconds(ms_delay)), thread(&TargetState::thread_proc, this) @@ -42,12 +43,15 @@ bool TargetState::signal_event(unsigned vk_code, bool key_down) INPUT input[3] = { {}, {}, {} }; input[0].type = INPUT_KEYBOARD; input[0].ki.wVk = 0xCF; + input[0].ki.dwExtraInfo = CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG; input[1].type = INPUT_KEYBOARD; input[1].ki.wVk = 0xCF; input[1].ki.dwFlags = KEYEVENTF_KEYUP; + input[1].ki.dwExtraInfo = CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG; input[2].type = INPUT_KEYBOARD; input[2].ki.wVk = VK_LWIN; input[2].ki.dwFlags = KEYEVENTF_KEYUP; + input[2].ki.dwExtraInfo = CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG; SendInput(3, input, sizeof(INPUT)); } return supress;