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:
52
src/modules/fancyzones/FancyZonesLib/KeyState.h
Normal file
52
src/modules/fancyzones/FancyZonesLib/KeyState.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "GenericKeyHook.h"
|
||||
|
||||
template<int... keys>
|
||||
class KeyState
|
||||
{
|
||||
public:
|
||||
KeyState(const std::function<void()>& callback) :
|
||||
m_state(false),
|
||||
m_hook(std::bind(&KeyState::onChangeState, this, std::placeholders::_1)),
|
||||
m_updateCallback(callback)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline bool state() const noexcept { return m_state; }
|
||||
|
||||
inline void enable()
|
||||
{
|
||||
m_hook.enable();
|
||||
m_state = (((GetAsyncKeyState(keys) & 0x8000) || ...));
|
||||
}
|
||||
|
||||
inline void disable()
|
||||
{
|
||||
m_hook.disable();
|
||||
}
|
||||
|
||||
inline void setState(bool state) noexcept
|
||||
{
|
||||
if (m_state != state)
|
||||
{
|
||||
m_state = state;
|
||||
if (m_updateCallback)
|
||||
{
|
||||
m_updateCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
inline void onChangeState(bool state) noexcept
|
||||
{
|
||||
setState(state);
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<bool> m_state;
|
||||
GenericKeyHook<keys...> m_hook;
|
||||
std::function<void()> m_updateCallback;
|
||||
};
|
||||
Reference in New Issue
Block a user