diff options
| author | a1xd <[email protected]> | 2021-07-06 16:10:52 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-07-06 16:12:31 -0400 |
| commit | 9f1ebe0feaaaf1eef1ffa5706d270b7600edfc63 (patch) | |
| tree | c700e644fd96e93aa4b19cd72eaefe9cb21fa066 /common | |
| parent | merge lut2 (diff) | |
| download | rawaccel-9f1ebe0feaaaf1eef1ffa5706d270b7600edfc63.tar.xz rawaccel-9f1ebe0feaaaf1eef1ffa5706d270b7600edfc63.zip | |
fix typo and wrapper/input code from lut2 merge
Diffstat (limited to 'common')
| -rw-r--r-- | common/common.vcxitems | 1 | ||||
| -rw-r--r-- | common/utility-rawinput.hpp | 103 |
2 files changed, 0 insertions, 104 deletions
diff --git a/common/common.vcxitems b/common/common.vcxitems index 2cf2df2..296fbfd 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -31,7 +31,6 @@ <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" /> - <ClInclude Include="$(MSBuildThisFileDirectory)utility-rawinput.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" /> </ItemGroup> diff --git a/common/utility-rawinput.hpp b/common/utility-rawinput.hpp deleted file mode 100644 index f04b2c1..0000000 --- a/common/utility-rawinput.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#pragma comment(lib, "cfgmgr32.lib") - -#include <algorithm> -#include <string> -#include <system_error> -#include <vector> - -#include <Windows.h> -#include <cfgmgr32.h> -#include <initguid.h> // needed for devpkey.h to parse properly -#include <devpkey.h> - -template <typename Func> -void rawinput_foreach_dev_with_id(Func fn, bool with_instance_id = false, - DWORD input_type = RIM_TYPEMOUSE) -{ - const UINT RI_ERROR = -1; - - // get number of devices - UINT num_devs = 0; - if (GetRawInputDeviceList(NULL, &num_devs, sizeof(RAWINPUTDEVICELIST)) != 0) { - throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceList failed"); - } - - auto devs = std::vector<RAWINPUTDEVICELIST>(num_devs); - - if (GetRawInputDeviceList(&devs[0], &num_devs, sizeof(RAWINPUTDEVICELIST)) == RI_ERROR) { - return; - } - - std::wstring name; - std::wstring id; - DEVPROPTYPE type; - CONFIGRET cm_res; - - for (auto&& dev : devs) { - if (dev.dwType != input_type) continue; - - // get interface name length - UINT name_len = 0; - if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, NULL, &name_len) == RI_ERROR) { - continue; - } - - name.resize(name_len); - - if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, &name[0], &name_len) == RI_ERROR) { - continue; - } - - // get sizeof dev instance id - ULONG id_size = 0; - cm_res = CM_Get_Device_Interface_PropertyW(&name[0], &DEVPKEY_Device_InstanceId, - &type, NULL, &id_size, 0); - - if (cm_res != CR_BUFFER_SMALL && cm_res != CR_SUCCESS) continue; - - id.resize((id_size + 1) / 2); - - cm_res = CM_Get_Device_Interface_PropertyW(&name[0], &DEVPKEY_Device_InstanceId, - &type, reinterpret_cast<PBYTE>(&id[0]), &id_size, 0); - - if (cm_res != CR_SUCCESS) continue; - - if (!with_instance_id) { - auto instance_delim_pos = id.find_last_of('\\'); - if (instance_delim_pos != std::string::npos) id.resize(instance_delim_pos); - } - - fn(dev, id); - } -} - -inline -std::vector<HANDLE> rawinput_handles_from_dev_id(const std::wstring& device_id, - bool with_instance_id = false, - DWORD input_type = RIM_TYPEMOUSE) -{ - std::vector<HANDLE> handles; - - rawinput_foreach_dev_with_id([&](const auto& dev, const std::wstring& id) { - if (id == device_id) handles.push_back(dev.hDevice); - }, with_instance_id, input_type); - - return handles; -} - -inline -std::vector<std::wstring> rawinput_dev_id_list(bool with_instance_id = false, - DWORD input_type = RIM_TYPEMOUSE) -{ - std::vector<std::wstring> ids; - - rawinput_foreach_dev_with_id([&](const auto& dev, const std::wstring& id) { - ids.push_back(id); - }, with_instance_id, input_type); - - std::sort(ids.begin(), ids.end()); - ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); - return ids; -} |