mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
#pragma once
|
|
#include <Windows.h>
|
|
|
|
/*
|
|
ll_keyboard - Lowlevel Keyboard Hook
|
|
|
|
The PowerToys runner installs low-level keyboard hook using
|
|
SetWindowsHookEx(WH_KEYBOARD_LL, ...)
|
|
See https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644985(v%3Dvs.85)
|
|
for details.
|
|
|
|
When a keyboard event is signaled and ncCode equals HC_ACTION, the wParam
|
|
and lParam event parameters are passed to all subscribed clients in
|
|
the LowlevelKeyboardEvent struct.
|
|
|
|
The intptr_t data event argument is a pointer to the LowlevelKeyboardEvent struct.
|
|
|
|
A non-zero return value from any of the subscribed PowerToys will cause
|
|
the runner hook proc to return 1, thus swallowing the keyboard event.
|
|
|
|
Example usage, that makes Windows ignore the L key:
|
|
|
|
virtual intptr_t signal_event(const wchar_t* name, intptr_t data) override {
|
|
if (wcscmp(name, ll_keyboard) == 0) {
|
|
auto& event = *(reinterpret_cast<LowlevelKeyboardEvent*>(data));
|
|
// The L key has vkCode of 0x4C
|
|
if (event.wParam == WM_KEYDOWN && event.lParam->vkCode == 0x4C) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
*/
|
|
|
|
namespace {
|
|
const wchar_t* ll_keyboard = L"ll_keyboard";
|
|
}
|
|
|
|
struct LowlevelKeyboardEvent {
|
|
KBDLLHOOKSTRUCT* lParam;
|
|
WPARAM wParam;
|
|
};
|