0

I am writing a small proof of concept for detecting extra inputs across mouses and keyboards on Windows, is it possible and how do I go about detecting input from a large amount of buttons in the Windows API? From what I have read, there is only support for 5 buttons but many mice have more buttons than that, is my question even possible with the Windows API, is it possible at all within the constraints of Windows?

2 Answers 2

2

You can use the Raw Input API to receive WM_INPUT messages directly from the mouse/keyboard driver. There are structure fields for the 5 standard mouse buttons (left, middle, right, x1, and x2). Beyond the standard buttons, additional buttons are handled by vendor-specific data that you would have to code for as needed. The API can give you access to the raw values, but you will have to refer to the vendor driver documentation for how to interpret them. Sometimes extra buttons are actually reported as keyboard input instead of mouse input.

Or, try using the DirectInput API to interact with DirectInput devices to receive Mouse Data and Keyboard Data.

Or, you could use the XInput API, which is the successor of DirectInput. However, XInput is more limited than DirectInput, as it is designed primarily for interacting with the Xbox 360 controller, whereas DirectInput is designed to interact with any controller. See XInput and DirectInput for more details.

2
  • I see, so there really isn't a cookie cutter answer. I would have to account for every hardware manufacturer's specific driver.
    – Stephen
    Apr 6, 2016 at 22:46
  • If you use the Raw Input API, yes. DirectInput is a bit more flexible and generic, and can handle up to 128 buttons (though I don't know how it handles more than 8 buttons at a time, which is the max that DIMOUSESTATE2 can handle when calling IDirectInputDevice8::GetDeviceState()). Apr 6, 2016 at 23:07
0

Very simple: use GetKeyState

SHORT WINAPI GetKeyState(
  _In_ int nVirtKey
);

Logic is next:

  1. Ask user not to press buttons
  2. Loop GetKeyState for all buttons 0-255
  3. Drop pressed buttons state (some virtual keys can be pressed even it not pressed, not know why)
  4. Now start keys monitor thread for rest keys codes and save them to any structure (pause between loop is 25ms is enough)
  5. Ask user to press button
  6. From keys monitor array you will see the any pressed buttons by user

Direct input and all other is more usable for other user input devices. For keyboard and mouse - GetKeyState is best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.