summaryrefslogtreecommitdiff
path: root/common/rawaccel-io.hpp
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-07-31 20:04:19 -0400
committera1xd <[email protected]>2020-07-31 20:04:19 -0400
commit5241f9783b41e74f719dc4a472c6b0803b0eff8c (patch)
tree4c0a0507610e30b5c76b0dfff98e50b56993f8ae /common/rawaccel-io.hpp
parentMerge pull request #7 from JacobPalecki/GUI (diff)
downloadrawaccel-5241f9783b41e74f719dc4a472c6b0803b0eff8c.tar.xz
rawaccel-5241f9783b41e74f719dc4a472c6b0803b0eff8c.zip
add read
add function that makes an ioctl call to return the driver's active mouse_modifier
Diffstat (limited to 'common/rawaccel-io.hpp')
-rw-r--r--common/rawaccel-io.hpp46
1 files changed, 46 insertions, 0 deletions
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 <system_error>
+
+#define NOMINMAX
+#include <Windows.h>
+
+#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;
+ }
+
+}