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 (110 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 (20,923 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 (60 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 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 webmaster@godotengine.org with your username.