This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+6 votes

How do I get input from the mouse wheel? For example, for zooming in an out of the map in a strategy game.

The "Wheel Up Button" in Input doesn't seem to work, unfortunately. My mouse scrolls smoothly with no buttons. I think what I need is an analog input rather than an on/off value.

I'm using Godot 3.0.5 and C# but it should be roughly the same for GDscript.

in Engine by (112 points)
edited by

3 Answers

+6 votes
Best answer

This is the way to capture wheel mouse in Godot from C#.

public override void _UnhandledInput(InputEvent @event){
    if (@event is InputEventMouseButton){
        InputEventMouseButton emb = (InputEventMouseButton)@event;
        if (emb.IsPressed()){
            if (emb.ButtonIndex == (int)ButtonList.WheelUp){
            if (emb.ButtonIndex == (int)ButtonList.WheelDown){
by (62 points)
selected by
+21 votes

I don't know about C#, but I have this GDScript code for zooming:

if event is InputEventMouseButton:
    if event.is_pressed():
        # zoom in
        if event.button_index == BUTTON_WHEEL_UP:
            zoom_pos = get_global_mouse_position()
            # call the zoom function
        # zoom out
        if event.button_index == BUTTON_WHEEL_DOWN:
            zoom_pos = get_global_mouse_position()
            # call the zoom function
by (569 points)
+25 votes

Or you could just use:if Input.is_action_just_released(your thing)(gdscript)
The Wheel Up Button only has a just released function.

by (34 points)

Thank you very much!

Thanks. Curious if/where this nugget is buried in the docs.

I don't know if this quirk is mentioned in the docs actually, I think I found it out by trial and error lol.

thanks.. unlike InputMouseEvent which able to detect both pressed and not pressed. the InputMap only viable with just_released method. Which is obvious..

This doesn't work, because this just makes it zoom forever until it reaches the limit. I want it to only zoom when I'm scrolling.

This was the answer I was looking for! Thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.