Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Raw input not working #61

Open
malhotraprateek opened this issue Aug 14, 2018 · 4 comments
Open

Raw input not working #61

malhotraprateek opened this issue Aug 14, 2018 · 4 comments

Comments

@malhotraprateek
Copy link

I want to work with raw input (windows) and thought this library was a good fit for me.
I tried to modify the listener example to use raw input but was not able to do so.

Steps to reproduce:

  1. Build the project for x64 (I used VS2017 Community)

  2. Change the following code snippet in listenersample.cpp:
    manager.CreateDevice<gainput::InputDeviceKeyboard>(gainput::InputDevice::DV_RAW);
    const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>();
    manager.CreateDevice<gainput::InputDeviceMouse>(gainput::InputDevice::DV_RAW);
    const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>();
    manager.CreateDevice<gainput::InputDevicePad>();
    manager.CreateDevice<gainput::InputDevicePad>();
    manager.CreateDevice<gainput::InputDeviceTouch>();
    to
    const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>(gainput::InputDevice::AutoIndex, gainput::InputDevice::DV_RAW);
    //manager.CreateDevice<gainput::InputDeviceKeyboard>();
    const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>(gainput::InputDevice::AutoIndex, gainput::InputDevice::DV_RAW);
    //manager.CreateDevice<gainput::InputDeviceMouse>();
    //manager.CreateDevice<gainput::InputDevicePad>();
    //manager.CreateDevice<gainput::InputDevicePad>();
    //manager.CreateDevice<gainput::InputDeviceTouch>();

  3. Run the sample project

  4. Observe that there is no mouse input being reported

Potential solution:

I believe that the problem lies in how the library gets the raw input data in GainputInputDeviceMouseWinRaw.h and GainputInputDeviceKeyboardWinRaw.h

For x64 dwSize variable must be 48 instead of 40. A better way would be to get the size needed from the system itself.

Check the revisions of this gist.

NOTE: I have used C++ 11 features (shared_ptr) for my modifications.

Kindly let me know if you need anything more from my side

@kowalej
Copy link

kowalej commented May 12, 2019

@malhotraprateek are you trying to get all system input or only input within your application window?

@malhotraprateek
Copy link
Author

@kowalej
Hi, I was trying to create a Vulkan demo application. It think it was intended to be a windowed application and did not capture all system input.
It has been sometime now, so I may not remember correctly.

@kowalej
Copy link

kowalej commented May 13, 2019

My purposes were capturing all input inside and outside the focused window but perhaps this may help you:

Set flags RIDEV_INPUTSINK | RIDEV_DEVNOTIFY and for hWnd give it the handle to your applications window.

Read more about the flags and such here:
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagrawinputdevice

@malhotraprateek
Copy link
Author

The issue I observed was that the lpb byte array was declared to have a size of 40 but the OS was returning 48 instead.
I believe the correct size can be determined by calling GetRawInputData with nullptr for the third parameter and does not need to be hard-coded.
(See references)

Does the size of input data buffer depend upon RIDEV_* flags?

References:
MS Documentation
This blog post
This stack-overflow question has some more useful info.

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

No branches or pull requests

2 participants