Game Development Community

Mouse Wheel Event Fires Continuously

by Robert Schmidt · in Torque X 2D · 06/03/2008 (2:58 pm) · 3 replies

I've mapped the mouse wheel input with the following code;

inputMap.BindAction(mouseId, (int)XMouseDevice.MouseObjects.Wheel, TorqueInputDevice.Action.None, OnMouseScroll);

but when the wheel is turned, even one notch the OnMouseScroll event handler is called continuously. It won't stop unless I rotate the wheel one notch in the opposite direction. I would expect that the event should stop firing if the wheel is no longer being turned. I wasn't able to find any way to turn this off in code and found no other posts on this issue. I tried mapping the input using BindMove and BindCommand but in both cases the event handler was no longer called at all when the wheel was turned. Has anyone else encountered this?

#1
06/04/2008 (1:38 am)
You might then have to have a work around. Like storing the value of the amount it turns by. Does it give this kind of value? And check if there is a difference of current and previous values.
#2
06/04/2008 (12:15 pm)
I gave up on using BindAction with the mouse wheel and went with this:

float scrollDelta;
            MouseState mouse = Mouse.GetState();

            //initialize _scrollWheelPrevious if uninitialized
            if (_scrollWheelPrevious == -1)
                _scrollWheelPrevious = mouse.ScrollWheelValue;

            scrollDelta = mouse.ScrollWheelValue - _scrollWheelPrevious;
            _scrollWheelPrevious = mouse.ScrollWheelValue;
private int _scrollWheelPrevious = -1;

scrollDelta should give you what you're looking for.
#3
06/04/2008 (1:11 pm)
Thanks, that works fine. I'm not happy that cycles are being wasted raising events for no reason though. I am assuming this is a bug then. Seems the mouse in general is not really supported in this version.