diff --git a/src/modules/interface/powertoy_module_interface.h b/src/modules/interface/powertoy_module_interface.h index 723ef8fb1c..db49afd582 100644 --- a/src/modules/interface/powertoy_module_interface.h +++ b/src/modules/interface/powertoy_module_interface.h @@ -125,6 +125,10 @@ public: return powertoys_gpo::gpo_rule_configured_not_configured; } + // Some actions like PastePlain generate new inputs, which we don't want to catch again. + // The flag was purposefully chose to not collide with other keyboard manager flags. + const static inline ULONG_PTR CENTRALIZED_KEYBOARD_HOOK_DONT_TRIGGER_FLAG = 0x110; + protected: HANDLE CreateDefaultEvent(const wchar_t* eventName) { diff --git a/src/modules/pasteplain/PastePlainModuleInterface/dllmain.cpp b/src/modules/pasteplain/PastePlainModuleInterface/dllmain.cpp index e3bfdb5600..1ad6578c82 100644 --- a/src/modules/pasteplain/PastePlainModuleInterface/dllmain.cpp +++ b/src/modules/pasteplain/PastePlainModuleInterface/dllmain.cpp @@ -311,6 +311,8 @@ private: INPUT input_event = {}; input_event.type = INPUT_KEYBOARD; input_event.ki.wVk = 0x56; // V + // Avoid triggering detection by the centralized keyboard hook. Allows using Control+V as activation. + input_event.ki.dwExtraInfo = CENTRALIZED_KEYBOARD_HOOK_DONT_TRIGGER_FLAG; inputs.push_back(input_event); } @@ -319,6 +321,8 @@ private: input_event.type = INPUT_KEYBOARD; input_event.ki.wVk = 0x56; // V input_event.ki.dwFlags = KEYEVENTF_KEYUP; + // Avoid triggering detection by the centralized keyboard hook. Allows using Control+V as activation. + input_event.ki.dwExtraInfo = CENTRALIZED_KEYBOARD_HOOK_DONT_TRIGGER_FLAG; inputs.push_back(input_event); } diff --git a/src/runner/centralized_kb_hook.cpp b/src/runner/centralized_kb_hook.cpp index 02b344b089..fcb96a09a7 100644 --- a/src/runner/centralized_kb_hook.cpp +++ b/src/runner/centralized_kb_hook.cpp @@ -88,6 +88,12 @@ namespace CentralizedKeyboardHook const auto& keyPressInfo = *reinterpret_cast(lParam); + if (keyPressInfo.dwExtraInfo == PowertoyModuleIface::CENTRALIZED_KEYBOARD_HOOK_DONT_TRIGGER_FLAG) + { + // The new keystroke was generated from one of our actions. We should pass it along. + return CallNextHookEx(hHook, nCode, wParam, lParam); + } + // Check if the keys are pressed. if (!pressedKeyDescriptors.empty()) {