Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Detecting the direction the mouse wheel is moving?

Asked by
Vexture 179
7 years ago
Edited 7 years ago

I can detect when the wheel is being used by using UserInputService, like so:

uis.InputChanged:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseWheel then
        print("WHEEL")
    end
end)

The problem is that I cannot get the direction (forward or backward) that the mouse wheel is moving.

I have even tried using a ScrollingFrame with the MouseWheelForward and MouseWheelBackward events to detect when either of those things happen, but those events don't seem to fire.

Is there any other way I can detect the direction the mouse wheel is scrolling?

1 answer

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

You're on the right track actually! You need to check the sign of the Z component in the Position property of the inputobject!

uis.InputChanged:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseWheel then
        print("WHEEL GOING " .. input.Position.Z > 0 and "UP" or "DOWN")
    end
end)
Ad

Answer this question