Stephen
Stephen

Reputation: 1518

Support for up to eleven mouse buttons?

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?

Upvotes: 0

Views: 1772

Answers (2)

VoidVolker
VoidVolker

Reputation: 1029

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.

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 596186

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.

Upvotes: 2

Related Questions