Mathyn's picture

OpenTK.Input.Mouse not working on Windows 8

Recently I installed Windows 8 on my computer. After checking if my programs still worked I discovered that all mouse input using the OpenTK.Input namespace no longer works.

When I call:
OpenTK.Input.MouseState mouseState= OpenTK.Input.Mouse.GetState();
it only reports mouseState.IsConnected is false.

It worked just fine on windows 7, which leads me to believe it is a problem with Windows 8 and/or OpenTK.

Could anyone verify this problem? I would like to be sure before making a topic in the issues forum.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
comwizz2's picture

I previously posted for help regarding mouse, I also am using windows 8, that may be part of the reason. I got the same wierd issue where no mouse is connected No one ever responded to my post, so I've been using using system.windows.forms.cursor.pointer as a work around, but i would really like to see this issue as resolved. Seeing as how i am not the only one with the issue ill file a bug report. I don't know anything about raw input or i might try to fix it myself.

Mathyn's picture

Good to here I am not the only one with this problem. Now let's hope this problem will be fixed :)

thomasd3's picture

same here; keyboard doesn't work either on Windows 8 btw.
I'm going to have a look today at the problem for the keyboard.

thomasd3's picture

I found something; it's keyboard related, but I believe the mouse is the same problem:
The code below is WinRawKeyboard.cs

On my machine (Win 8 running in a VM on a Mac); it finds 5 raw devices and two fit in the keyboard category and enter the test below.
The line where it gets the device class returns a null string and this causes the last test of this snippet to fail and not register the device with OpenTK.

I'm going to check my other computer (Win 7) to make sure it's different, but it is very likely, otherwise devices wouldn't get registered from what I've seen of the code.

btw, if I force deviceClass to be 'keyboard', the keyboard works.

                    else if (dev.Type == RawInputDeviceType.KEYBOARD || dev.Type == RawInputDeviceType.HID)
                    {
                        // This is a keyboard or USB keyboard device. In the latter case, discover if it really is a
                        // keyboard device by qeurying the registry.
                        RegistryKey regkey = GetRegistryKey(name);
                        string deviceDesc = (string)regkey.GetValue("DeviceDesc");
                        string deviceClass = (string)regkey.GetValue("Class");
 
                        if (String.IsNullOrEmpty(deviceDesc))
                        {
                            Debug.Print("[Warning] Failed to retrieve device description, skipping this device.");
                            continue;
                        }
                        else
                        {
                            deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);
                        }
 
                        if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("keyboard"))
                        {
                            // Register the keyboard:
                            RawInputDeviceInfo info = new RawInputDeviceInfo();
                            int devInfoSize = API.RawInputDeviceInfoSize;
                            Functions.GetRawInputDeviceInfo(dev.Device, RawInputDeviceInfoEnum.DEVICEINFO,
                                    info, ref devInfoSize);
thomasd3's picture

I know the problem now; it applies to both Keyboard and Mouse:

The code below tries to get the device class:
string deviceClass = (string)regkey.GetValue("Class");

In Win 8, the 'Class' field does NOT exist. it has only 'ClassGUID'.
ClassGUID contains a GUID from HKLM/System/CurrentControlSet/Control/Class that contains the class value.
An extra indirection is needed to make this work.

Win 7 contains ClassGUID as well, so a fix will work on Win 7 as well.

I will make a patch and post it here; I can test it on Win 7 and Win 8, but I do not have Vista nor XP, so someone will have to test it to verify compatibility.

thomasd3's picture

This is the keyboard patch.
The file is WinRawKeyboard.cs, around line 100

                        RegistryKey regkey = GetRegistryKey(name);
                        string deviceDesc = (string)regkey.GetValue("DeviceDesc");
 
                      //string deviceClass = (string)regkey.GetValue("Class");
	               string deviceClassGUID = (string)regkey.GetValue("ClassGUID");
                       RegistryKey classGUIDKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + deviceClassGUID);
                       string deviceClass = classGUIDKey != null ? (string) classGUIDKey.GetValue("Class") : string.Empty;

I'm going to do the mouse patch right now.

thomasd3's picture

And here is the patch for the mouse.

The file is WinRawMouse.cs, around line 110:

                       // This is a mouse or a USB mouse device. In the latter case, discover if it really is a
                        // mouse device by qeurying the registry.
                        RegistryKey regkey = FindRegistryKey(name);
                        string deviceDesc = (string)regkey.GetValue("DeviceDesc");
COMMENT THIS LINE:                        //string deviceClass = (string)regkey.GetValue("Class");
                        deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);
 
ADD THIS:
			string deviceClassGUID = (string)regkey.GetValue("ClassGUID");
			RegistryKey classGUIDKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + deviceClassGUID);
	                string deviceClass = classGUIDKey != null ? (string) classGUIDKey.GetValue("Class") : string.Empty;

Can someone check this on Win Vista and XP and confirm here it works?

Mathyn's picture

Good find! Is there any possibility this could be added to the OpenTK code by default?

thomasd3's picture

I think it should, but we need to verify compatibility with XP and Vista first.

We can always check if the class exists and run the new code only if it doesn't; this would only add one test and guarantee compatibility.

Who's the maintainer of the repository?

AndyKorth's picture

Hi, if anyone has verified this in earlier Windows, let me know. I can look into getting a Windows machine set up, I might have to at some point.

I've been porting a lot of input fixes lately, so I'd like to port it to my repository here: https://github.com/andykorth/opentk So people will be able to get a working copy of the library. I'm hoping these changes will be ported into the official library at some point.