mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[FancyZones]Use RawInput to detect Shift key, fix locking out Shift key (#32116)
* init RawInputDevice * static * handle input * replace keyboard hooks (ctrl, shift) * keep ctrl hook * spellcheck
This commit is contained in:
43
src/modules/fancyzones/FancyZonesLib/KeyboardInput.cpp
Normal file
43
src/modules/fancyzones/FancyZonesLib/KeyboardInput.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "pch.h"
|
||||
#include "KeyboardInput.h"
|
||||
|
||||
#include <hidUsage.h>
|
||||
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
bool KeyboardInput::Initialize(HWND window)
|
||||
{
|
||||
RAWINPUTDEVICE inputDevice{};
|
||||
inputDevice.usUsagePage = HID_USAGE_PAGE_GENERIC;
|
||||
inputDevice.usUsage = HID_USAGE_GENERIC_KEYBOARD;
|
||||
inputDevice.dwFlags = RIDEV_INPUTSINK;
|
||||
inputDevice.hwndTarget = window;
|
||||
|
||||
bool res = RegisterRawInputDevices(&inputDevice, 1, sizeof(inputDevice));
|
||||
if (!res)
|
||||
{
|
||||
Logger::error(L"RegisterRawInputDevices error: {}", get_last_error_or_default(GetLastError()));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::optional<KeyboardInput::Key> KeyboardInput::OnKeyboardInput(HRAWINPUT hInput)
|
||||
{
|
||||
RAWINPUT input;
|
||||
UINT size = sizeof(input);
|
||||
auto result = GetRawInputData(hInput, RID_INPUT, &input, &size, sizeof(RAWINPUTHEADER));
|
||||
if (result < sizeof(RAWINPUTHEADER))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (input.header.dwType == RIM_TYPEKEYBOARD)
|
||||
{
|
||||
bool pressed = (input.data.keyboard.Flags & RI_KEY_BREAK) == 0;
|
||||
return KeyboardInput::Key{ input.data.keyboard.VKey, pressed };
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
Reference in New Issue
Block a user