From 5241f9783b41e74f719dc4a472c6b0803b0eff8c Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 31 Jul 2020 20:04:19 -0400 Subject: add read add function that makes an ioctl call to return the driver's active mouse_modifier --- common/rawaccel-io.hpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 common/rawaccel-io.hpp (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp new file mode 100644 index 0000000..5d6fad6 --- /dev/null +++ b/common/rawaccel-io.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include + +#define NOMINMAX +#include + +#include "rawaccel.hpp" + +#define RA_IOCTL CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS) + +namespace rawaccel { + + mouse_modifier read() { + HANDLE ra_handle = INVALID_HANDLE_VALUE; + + ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); + + if (ra_handle == INVALID_HANDLE_VALUE) { + throw std::system_error(GetLastError(), std::system_category(), "CreateFile failed"); + } + + mouse_modifier mod; + DWORD dummy; + + BOOL success = DeviceIoControl( + ra_handle, + RA_IOCTL, + NULL, // input buffer + 0, // input buffer size + &mod, // output buffer + sizeof(mouse_modifier), // output buffer size + &dummy, // bytes returned + NULL // overlapped structure + ); + + CloseHandle(ra_handle); + + if (!success) { + throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); + } + + return mod; + } + +} -- cgit v1.2.3 From 66a4043a9ecb1990878bea230f213708c7fdd3da Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 31 Jul 2020 20:19:24 -0400 Subject: move write function into common io header --- common/rawaccel-io.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 5d6fad6..7a4c59c 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -43,4 +43,33 @@ namespace rawaccel { return mod; } + void write(mouse_modifier mod) { + HANDLE ra_handle = INVALID_HANDLE_VALUE; + + ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); + + if (ra_handle == INVALID_HANDLE_VALUE) { + throw std::system_error(GetLastError(), std::system_category(), "CreateFile failed"); + } + + DWORD dummy; + + BOOL success = DeviceIoControl( + ra_handle, + RA_IOCTL, + &mod, // input buffer + sizeof(mouse_modifier), // input buffer size + NULL, // output buffer + 0, // output buffer size + &dummy, // bytes returned + NULL // overlapped structure + ); + + CloseHandle(ra_handle); + + if (!success) { + throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); + } + } + } -- cgit v1.2.3 From b49a91627faa6411023f7823250337cc1a71af82 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 31 Jul 2020 20:36:17 -0400 Subject: move clipp/parse logic into console project --- common/rawaccel-io.hpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 7a4c59c..4050f07 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -9,6 +9,9 @@ #define RA_IOCTL CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS) +#pragma warning(push) +#pragma warning(disable:4245) // int -> DWORD conversion while passing RA_IOCTL + namespace rawaccel { mouse_modifier read() { @@ -43,6 +46,7 @@ namespace rawaccel { return mod; } + void write(mouse_modifier mod) { HANDLE ra_handle = INVALID_HANDLE_VALUE; @@ -73,3 +77,5 @@ namespace rawaccel { } } + +#pragma warning(pop) -- cgit v1.2.3