mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[FancyZones] Move FancyZones out of the runner process (#11818)
* rename dll -> FancyZonesModuleInterface (#11488) * [FancyZones] Rename "fancyzones/tests" -> "fancyzones/FancyZonesTests" (#11492) * [FancyZones] Rename "fancyzones/lib" -> "fancyzones/FancyZonesLib" (#11489) * [FancyZones] New FancyZones project. (#11544) * [FancyZones] Allow single instance of "PowerToys.FancyZones.exe" (#11558) * [FancyZones] Updated bug reports (#11571) * [FancyZones] Updated installer (#11572) * [FancyZones] Update string resources (#11596) * [FancyZones] Terminate FancyZones with runner (#11696) * [FancyZones] Drop support for the module interface API to save settings (#11661) * Settings telemetry for FancyZones (#11766) * commented out test * enable dpi awareness for the process
This commit is contained in:
60
src/modules/fancyzones/FancyZonesLib/GenericKeyHook.h
Normal file
60
src/modules/fancyzones/FancyZonesLib/GenericKeyHook.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
#include <functional>
|
||||
#include <common/debug_control.h>
|
||||
|
||||
template<int... keys>
|
||||
class GenericKeyHook
|
||||
{
|
||||
public:
|
||||
|
||||
GenericKeyHook(std::function<void(bool)> extCallback)
|
||||
{
|
||||
callback = std::move(extCallback);
|
||||
}
|
||||
|
||||
void enable()
|
||||
{
|
||||
#if defined(DISABLE_LOWLEVEL_HOOKS_WHEN_DEBUGGED)
|
||||
if (IsDebuggerPresent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!hHook)
|
||||
{
|
||||
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, GenericKeyHookProc, GetModuleHandle(NULL), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
if (hHook)
|
||||
{
|
||||
UnhookWindowsHookEx(hHook);
|
||||
hHook = NULL;
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
inline static HHOOK hHook = nullptr;
|
||||
inline static std::function<void(bool)> callback;
|
||||
|
||||
static LRESULT CALLBACK GenericKeyHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (nCode == HC_ACTION)
|
||||
{
|
||||
if (wParam == WM_KEYDOWN || wParam == WM_KEYUP)
|
||||
{
|
||||
PKBDLLHOOKSTRUCT kbdHookStruct = (PKBDLLHOOKSTRUCT)lParam;
|
||||
if (((kbdHookStruct->vkCode == keys) || ...))
|
||||
{
|
||||
callback(wParam == WM_KEYDOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(hHook, nCode, wParam, lParam);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user