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.
0 votes

Hello,
I trying Godot 3.0 Alpha and want to get mouse wheel scroll

If InputEventMouseButton.get_button_index ==BUTTON_WHEEL_UP:
      Print('wheel up!')

and getting error

Invalid get index 'get_button_index' (on base: GDNativeClass)

what I'm doing wrong?

Thank you in advance

in Engine by (111 points)

2 Answers

+1 vote
Best answer

First of all, if and print shouldn't be capitalized (I'm guessing that's a typo in your question, not in your code).

In 3.0 the event API has changed a bit (and hasn't yet been documented fully). An InputEvent is an object, and you check its type to see what it is. Depending on its type, you can access its members. For example:

func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_WHEEL_UP:
            print("wheel up!")

You can also use get_button_index() like in your question, but you would need the () because it's a function.

by (22,191 points)
selected by

now it is working. Thank you very much!

+1 vote

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){
                GD.Print(emb.AsText());
            }
            if (emb.ButtonIndex == (int)ButtonList.WheelDown){
                GD.Print(emb.AsText());
            }
        }
    }
}
by (62 points)
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.