Dealing with MouseWheel input

Started by
7 comments, last by yaroslavd 17 years, 9 months ago
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.
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.
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]
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?

--------------------------Most of what I know came from Frank D. Luna's DirectX books
Maybe, that's what I'm trying to figure out. Can't find anything so far, though.
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.
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.
SystemInformation.MouseWheelScrollDelta Property

--------------------------Most of what I know came from Frank D. Luna's DirectX books
Thank you. Rating+ all around!

This topic is closed to new replies.

Advertisement