Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot open game controller for raw input #12

Open
mat1jaczyyy opened this issue May 9, 2021 · 2 comments
Open

Cannot open game controller for raw input #12

mat1jaczyyy opened this issue May 9, 2021 · 2 comments

Comments

@mat1jaczyyy
Copy link

Hi @mfakane, I'm trying to use your wrapper to receive raw input from game controllers. Here's an example controller I'm trying to read:

image

I've tried to modify SimpleExample to use either HidUsageAndPage.Joystick or HidUsageAndPage.Gamepad, but there is a Win32ErrorException. RegisterRawInputDevices returns false with GetLastError = 87, which is "The parameter is incorrect.".

I also tried to directly access it like this as well:

            try
            {
                // Register the HidUsageAndPage to watch any device.
                RawInputDevice.RegisterDevice(devices[0].UsageAndPage, RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, window.Handle);

                Application.Run();
            }
            finally
            {
                RawInputDevice.UnregisterDevice(devices[0].UsageAndPage);
            }

I'm not sure if it's correct, but it returns the same error. What am I supposed to do?

@mat1jaczyyy
Copy link
Author

@mfakane Just a reminder, I'd really appreciate if you could find some time to give this a look, please 🙏

@pre-martin
Copy link

Your device has UsageAndPage 1:05, so you should register with:

RawInputDevice.RegisterDevice(HidUsageAndPage.GamePad, RawInputDeviceFlags.InputSink, _window.Handle);

NoLegacy is only relevant for mouse and keyboard devices (see https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevice). InputSink vs ExInputSink depends on your usage.

Is your window (or _window in my example) instance still valid, when you call RegisterDevice? I.e. that it is not out of scope and being garbage collected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants