Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Check the mouse deviceDesc before parsing it #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions Source/OpenTK/Platform/Windows/WinRawMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,27 @@ public void RefreshDevices()
RegistryKey regkey = FindRegistryKey(name);
string deviceDesc = (string)regkey.GetValue("DeviceDesc");
string deviceClass = (string)regkey.GetValue("Class");
deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);

if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse"))
if (!String.IsNullOrEmpty(deviceDesc))
{
if (!rawids.ContainsKey(new ContextHandle(dev.Device)))
deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);

if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse"))
{
// Register the device:
RawInputDeviceInfo info = new RawInputDeviceInfo();
int devInfoSize = API.RawInputDeviceInfoSize;
Functions.GetRawInputDeviceInfo(dev.Device, RawInputDeviceInfoEnum.DEVICEINFO,
info, ref devInfoSize);

RegisterRawDevice(Window, deviceDesc);
MouseState state = new MouseState();
state.IsConnected = true;
mice.Add(state);
names.Add(deviceDesc);
rawids.Add(new ContextHandle(dev.Device), mice.Count - 1);
if (!rawids.ContainsKey(new ContextHandle(dev.Device)))
{
// Register the device:
RawInputDeviceInfo info = new RawInputDeviceInfo();
int devInfoSize = API.RawInputDeviceInfoSize;
Functions.GetRawInputDeviceInfo(dev.Device, RawInputDeviceInfoEnum.DEVICEINFO,
info, ref devInfoSize);

RegisterRawDevice(Window, deviceDesc);
MouseState state = new MouseState();
state.IsConnected = true;
mice.Add(state);
names.Add(deviceDesc);
rawids.Add(new ContextHandle(dev.Device), mice.Count - 1);
}
}
}
}
Expand Down