Polling additional mouse buttons

a line with question marks pointing at side buttons of a mouse

Computer mice these days tend to have additional buttons on sides/ and people periodically wonder whether they need to do anything particular to poll these buttons.

Technical

Most operating systems allow mice to have 5 buttons total - left, right, middle (wheel click), "X1", and "X2", alongside with horizontal and vertical wheel events.

It is a little challenging to find any specific information on intended use of X1/X2 buttons (as far as software goes), so we can only assume that they were intended to be general-purpose.

Implementation

  • WinAPI (events)
    Use WM_XBUTTON* events and check wParam to see which button it is.
  • WinAPI (raw)
    Use GetAsyncKeyState or GetKeyboardState with VK_XBUTTON1 or VK_XBUTTON2.
  • GameMaker (Windows-related platforms)
    keyboard_check_direct(5) and keyboard_check_direct(6), respectively (as it calls GetAsyncKeyState).
  • GameMaker (rest of the platforms)
    You'll probably need a native extension.

However!

As support for X1/X2 buttons (and even horizontal scrolling outside of native components) remained considerably uncommon through the years, most additional buttons on mice simply emit keyboard events instead - either directly or with help of a driver.

For example, if your mouse has a "Back" button on it, that is most likely emitting a VK_BROWSER_BACK key press, or even simply Alt+Left.

So, what you really want is configurable controls/keyboard shortcuts (without restricting the range of allowed keys), although even otherwise, increasingly often mice come with configuration software that allows to remap the buttons, sometimes even on per-application basis:


Different mouse configuration apps: MSI, Redragon, Microsoft


So that's about all on this matter, really.

Related posts:

One thought on “Polling additional mouse buttons

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.