mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
init RawInputDevice
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <FancyZonesLib/FancyZonesWindowProcessing.h>
|
||||
#include <FancyZonesLib/FancyZonesWindowProperties.h>
|
||||
#include <FancyZonesLib/FancyZonesWinHookEventIDs.h>
|
||||
#include <FancyZonesLib/KeyboardInput.h>
|
||||
#include <FancyZonesLib/MonitorUtils.h>
|
||||
#include <FancyZonesLib/on_thread_executor.h>
|
||||
#include <FancyZonesLib/Settings.h>
|
||||
@@ -172,6 +173,7 @@ private:
|
||||
const HINSTANCE m_hinstance{};
|
||||
|
||||
HWND m_window{};
|
||||
KeyboardInput m_keyboardInput{};
|
||||
std::unique_ptr<WindowMouseSnap> m_windowMouseSnapper{};
|
||||
WindowKeyboardSnap m_windowKeyboardSnapper{};
|
||||
WorkAreaConfiguration m_workAreaConfiguration;
|
||||
@@ -220,7 +222,13 @@ FancyZones::Run() noexcept
|
||||
m_window = CreateWindowExW(WS_EX_TOOLWINDOW, NonLocalizable::ToolWindowClassName, L"", WS_POPUP, 0, 0, 0, 0, nullptr, nullptr, m_hinstance, this);
|
||||
if (!m_window)
|
||||
{
|
||||
Logger::error(L"Failed to create FancyZones window");
|
||||
Logger::critical(L"Failed to create FancyZones window");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_keyboardInput.Initialize(m_window))
|
||||
{
|
||||
Logger::critical(L"Failed to register raw input device");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
<ClInclude Include="FancyZonesData.h" />
|
||||
<ClInclude Include="GuidUtils.h" />
|
||||
<ClInclude Include="JsonHelpers.h" />
|
||||
<ClInclude Include="KeyboardInput.h" />
|
||||
<ClInclude Include="KeyState.h" />
|
||||
<ClInclude Include="FancyZonesData\LayoutHotkeys.h" />
|
||||
<ClInclude Include="Layout.h" />
|
||||
@@ -114,6 +115,7 @@
|
||||
<ClCompile Include="FancyZonesData\LayoutHotkeys.cpp">
|
||||
<PrecompiledHeaderFile>../pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="KeyboardInput.cpp" />
|
||||
<ClCompile Include="Layout.cpp" />
|
||||
<ClCompile Include="LayoutConfigurator.cpp" />
|
||||
<ClCompile Include="LayoutAssignedWindows.cpp" />
|
||||
|
||||
@@ -168,6 +168,9 @@
|
||||
<ClInclude Include="FancyZonesData\LastUsedVirtualDesktop.h">
|
||||
<Filter>Header Files\FancyZonesData</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="KeyboardInput.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
@@ -278,6 +281,9 @@
|
||||
<ClCompile Include="FancyZonesWindowProcessing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="KeyboardInput.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
24
src/modules/fancyzones/FancyZonesLib/KeyboardInput.cpp
Normal file
24
src/modules/fancyzones/FancyZonesLib/KeyboardInput.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#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;
|
||||
}
|
||||
10
src/modules/fancyzones/FancyZonesLib/KeyboardInput.h
Normal file
10
src/modules/fancyzones/FancyZonesLib/KeyboardInput.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class KeyboardInput
|
||||
{
|
||||
public:
|
||||
KeyboardInput() = default;
|
||||
~KeyboardInput() = default;
|
||||
|
||||
bool Initialize(HWND window);
|
||||
};
|
||||
Reference in New Issue
Block a user