• Advertisement
Sign in to follow this  

Dealing with MouseWheel input

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. I'm using C#, MDX, and DirectInput. I have a MouseInput class which works wonders. However, the MouseState.Z member which is supposed to return how much the mouse wheel has turned works in a mysterious way. Basically, it works but every time I turn the wheel and from one "click" to the next, it returns that as 120 instead of 1. Now of course you could say "Why don't you just divide by 120 and you've got the right number of "clicks" the mouse wheel has turned?" The problem is, how can I be sure that on someone else's computer one "click" will not return 200 or 500 or whatever? So is there a way to check how much each "click" is worth or to simply return the number of "clicks?" Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Well, the managed documentation stinks, but search for GetGranularity (it's part of the DeviceProperties class accessable from Device.Properties). For the mouse wheel, it will return the number you're looking for. I just haven't figured out what to pass the method to specify that I'm interested in the wheel.

Share this post


Link to post
Share on other sites
Thanks a lot. I tried this:


Console.WriteLine("Mouse Granularity: {0}", _mouse.Properties.GetGranularity(ParameterHow.ByUsage, _mouse.DeviceInformation.Usage));




But got an UnsupportedException when the code is run.

[Edited by - yaroslavd on July 21, 2006 12:29:22 AM]

Share this post


Link to post
Share on other sites
In C++ there is a defined value for it:

/* Value for rolling one detent */
#define WHEEL_DELTA 120

Wouldn't there be something similar for managed code?

Share this post


Link to post
Share on other sites
Maybe, that's what I'm trying to figure out. Can't find anything so far, though.

Share this post


Link to post
Share on other sites
As DXnut stated, WHEEL_DELTA is what you are looking for. It is specified as 120 and since it is a const your program sets it.

Your code should handle getting non-multiples of 120, but 120 would still be the conceptual "one tick" even if someone's mouse took two ticks to get to 120. Large quantities of code are being written unable to handle such a result though, so it's your choice.

I am not familiar with what GetGranularity() does, but your "UnsupportedException" makes me guess it could be trying to get the information from the mouse itself. If this is the case, your device probably does not support this feature. Also keep in mind you should check the capabilities of a device prior to using functionality to prevent errors. You probably do this with GetCaps() for your video card.

Share this post


Link to post
Share on other sites
Where is this WHEEL_DATA specified in Managed DirectInput? And I'm pretty sure that my device supports it because my mouse has a wheel. I just have no idea what to pass to the function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement