summaryrefslogtreecommitdiff
path: root/grapher/Models/Mouse/MouseWatcher.cs
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2021-01-20 00:42:24 -0800
committerJacob Palecki <[email protected]>2021-01-20 00:42:24 -0800
commit77b4c7876918cac82494ec8fc15a22fdab5cf714 (patch)
tree66b2c7d86cecf0846c3b5cdaa69c6991858ed931 /grapher/Models/Mouse/MouseWatcher.cs
parentRemove debug statement (diff)
parentshow custom dialog on bad input (#63) (diff)
downloadrawaccel-77b4c7876918cac82494ec8fc15a22fdab5cf714.tar.xz
rawaccel-77b4c7876918cac82494ec8fc15a22fdab5cf714.zip
merge with master builds
Diffstat (limited to 'grapher/Models/Mouse/MouseWatcher.cs')
-rw-r--r--grapher/Models/Mouse/MouseWatcher.cs33
1 files changed, 26 insertions, 7 deletions
diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs
index 3cc8bd0..163829f 100644
--- a/grapher/Models/Mouse/MouseWatcher.cs
+++ b/grapher/Models/Mouse/MouseWatcher.cs
@@ -1,5 +1,6 @@
using grapher.Models.Serialized;
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@@ -398,7 +399,11 @@ namespace grapher.Models.Mouse
/// <summary>If set, the application-defined keyboard device hotkeys are not handled. However, the system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled. By default, all keyboard hotkeys are handled. NoHotKeys can be specified even if NoLegacy is not specified and WindowHandle is NULL.</summary>
NoHotKeys = 0x00000200,
/// <summary>If set, application keys are handled. NoLegacy must be specified. Keyboard only.</summary>
- AppKeys = 0x00000400
+ AppKeys = 0x00000400,
+ /// <summary>If set, this enables the caller to receive input in the background only if the foreground application does not process it. In other words, if the foreground application is not registered for raw input, then the background application that is registered will receive the input.</summary>
+ ExInputSink = 0x00001000,
+ /// <summary>If set, this enables the caller to receive WM_INPUT_DEVICE_CHANGE notifications for device arrival and device removal.</summary>
+ DevNotify = 0x00002000
}
/// <summary>Value type for raw input devices.</summary>
@@ -686,12 +691,13 @@ namespace grapher.Models.Mouse
AccelCharts = accelCharts;
SettingsManager = setMngr;
MouseData = new MouseData();
+ DeviceHandles = new List<IntPtr>();
RAWINPUTDEVICE device = new RAWINPUTDEVICE();
device.WindowHandle = ContainingForm.Handle;
device.UsagePage = HIDUsagePage.Generic;
device.Usage = HIDUsage.Mouse;
- device.Flags = RawInputDeviceFlags.InputSink;
+ device.Flags = RawInputDeviceFlags.InputSink | RawInputDeviceFlags.DevNotify;
RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1];
devices[0] = device;
@@ -716,6 +722,10 @@ namespace grapher.Models.Mouse
private Stopwatch Stopwatch { get; }
+ private List<IntPtr> DeviceHandles { get; }
+
+ private bool AnyDevice { get; set; }
+
private double PollTime
{
get => 1000 / SettingsManager.PollRateField.Data;
@@ -725,6 +735,16 @@ namespace grapher.Models.Mouse
#region Methods
+ public void UpdateHandles(string devID)
+ {
+ DeviceHandles.Clear();
+ AnyDevice = string.IsNullOrEmpty(devID);
+ if (!AnyDevice)
+ {
+ RawInputInterop.AddHandlesFromID(devID, DeviceHandles);
+ }
+ }
+
public void UpdateLastMove()
{
MouseData.Get(out var x, out var y);
@@ -733,15 +753,14 @@ namespace grapher.Models.Mouse
public void ReadMouseMove(Message message)
{
- RawInput rawInput = new RawInput();
- int outSize = 0;
+ RawInput rawInput;
int size = Marshal.SizeOf(typeof(RawInput));
-
- outSize = GetRawInputData((IntPtr)message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER)));
+ _ = GetRawInputData(message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER)));
bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute);
+ bool deviceMatch = AnyDevice || DeviceHandles.Contains(rawInput.Header.Device);
- if (relative && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0))
+ if (relative && deviceMatch && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0))
{
var time = Stopwatch.Elapsed.TotalMilliseconds;
Stopwatch.Restart();