1
\$\begingroup\$

I use Monogame for game development. For processing mouse input, I can use the Mouse class to query basic information like left click state, right click state, and screen position. That works fine for a generic three-button mouse (left, right, and scroll wheel), but falls short for more complex gaming mice with side buttons. My question is, how can I query those extra side buttons?

Since Mouse doesn't include that functionality, are there additional C# libraries I can use? How do I account for the fact that mice can have any number of extra buttons and wheels? Is there some standard for representing those additional buttons programatically?

Edit: This question originally also asked about complex keyboards with extra buttons or wheels. Now, I'm asking only about processing extra mouse buttons (ideally any number of extra buttons).

\$\endgroup\$
  • 1
    \$\begingroup\$ I recommend asking the keyboard question separately - otherwise you limit answers to those that can cover both at once, which might be a taller order. \$\endgroup\$ – DMGregory Nov 14 '17 at 2:02
1
+50
\$\begingroup\$

The 4-th and 5th buttons are known as XButton1 and XButton2 in Monogame and are available as properties on MouseState, either through Mouse.GetState or Window.MouseState

Old XNA documentation links and since I can't find any Monogame docs, a link to the source:

https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.mousestate.xbutton1.aspx

https://github.com/MonoGame/MonoGame/blob/47a47c9f0157d24cc9a581454cca1f11aa0adf51/MonoGame.Framework/Input/MouseState.cs#L30

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer. That's certainly useful information, and better than only the default mouse buttons, but I'm still curious about supporting additional buttons. Looks like Unity can natively support up to 7 mouse buttons. I'll award the bounty here if I don't see another answer in the next day or two. \$\endgroup\$ – Grimelios Nov 14 '17 at 4:21
  • \$\begingroup\$ AFAIK the windows API only returns up to 5 buttons unless you use DirectInput, so they probably didn't bother supporting any more. \$\endgroup\$ – Jimmy Nov 14 '17 at 5:09
  • \$\begingroup\$ see the comment chain at stackoverflow.com/questions/27655619/… or additional info \$\endgroup\$ – Jimmy Nov 14 '17 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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