[PastePlain]Support Ctrl+V as activation (#24448)

This commit is contained in:
Jaime Bernardo
2023-03-03 09:52:49 +00:00
committed by GitHub
parent 1fac3d3d1c
commit fa98fbd9f1
3 changed files with 14 additions and 0 deletions

View File

@@ -125,6 +125,10 @@ public:
return powertoys_gpo::gpo_rule_configured_not_configured; 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: protected:
HANDLE CreateDefaultEvent(const wchar_t* eventName) HANDLE CreateDefaultEvent(const wchar_t* eventName)
{ {

View File

@@ -311,6 +311,8 @@ private:
INPUT input_event = {}; INPUT input_event = {};
input_event.type = INPUT_KEYBOARD; input_event.type = INPUT_KEYBOARD;
input_event.ki.wVk = 0x56; // V 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); inputs.push_back(input_event);
} }
@@ -319,6 +321,8 @@ private:
input_event.type = INPUT_KEYBOARD; input_event.type = INPUT_KEYBOARD;
input_event.ki.wVk = 0x56; // V input_event.ki.wVk = 0x56; // V
input_event.ki.dwFlags = KEYEVENTF_KEYUP; 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); inputs.push_back(input_event);
} }

View File

@@ -88,6 +88,12 @@ namespace CentralizedKeyboardHook
const auto& keyPressInfo = *reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam); const auto& keyPressInfo = *reinterpret_cast<KBDLLHOOKSTRUCT*>(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. // Check if the keys are pressed.
if (!pressedKeyDescriptors.empty()) if (!pressedKeyDescriptors.empty())
{ {