Enable long press as right-click

Godot Version

4.2.1

Question

I found a setting called “Enable Long Press as Right Click” in the Project Settings > General > Input Devices > Pointing:

I’d love to use this, as it’d mean (if I understand correctly) that I can make my game with support for left and right clicks (so it works on a computer) and then it’ll automatically support Android too thanks to this setting.

However I’m having some issues with it…

I’ve setup a proof-of-concept project to test this: https://codeberg.org/BWPanda/random/raw/branch/master/input-test.zip

I couldn’t use the normal pressed signal for the button as I can’t seem to differentiate between left and right clicks then. So I used gui_input() instead, which lets me check which action was pressed/released.

This works - I can left-click and the button turns blue, or right-click and it turns red. On Android, I can tap the button and it turns blue, however when I press-and-hold the button turns blue and then red when I release.

So basically the left-click action is being triggered when pressing-and-holding the button in order to trigger the right-click action.

How do I make it so only the right-click action is trigger on press-and-hold?

Here’s the code:

func _on_gui_input(event):
    if get_global_rect().has_point(get_global_mouse_position()):
        if event.is_action_released("Primary"):
            $ColorRect.color = Color("blue")
        elif event.is_action_released("Secondary"):
            $ColorRect.color = Color("red")

        $Timer.start()


func _on_timer_timeout():
    $ColorRect.color = Color("white")

I suspect this is only for in-editor.

You could wire-up some kind of timer and use that to distinguish.

That doesn’t seem likely, especially since this option is under the heading “Android”… It’d be nice to know for sure.