Converting touch inputs to mouse inputs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BruhMoment24

I want to add mobile functionality by converting touch inputs (e.g. tap, hold, double tap) to mouse inputs but not sure how.

Specifically I would like for single tap to be mouse hover, double tap to be left mouse, and hold to be right mouse.

Is there anyway I can just convert the inputs to be mouse inputs using something like the input map?

Wait what? I’m really confused for some reason, do mind elaborating just a little bit more.

Also what device are you targeting?

umma | 2023-01-16 17:01

So I have some code for a 4D minesweeper game which I wanted to port to my android phone.

In the input function it uses the mouse position and button_index properties to highlight and click certain squares. How do I make it so that the hover code activates on tap? Likewise with the other actions.

I can post the _input function if helpful but I mostly just want to find a way to convert a tap to be a mouse hover, a double tap to be a mousedown with buttonindex 1, and a hold to be a mousedown with buttonindex 2

BruhMoment24 | 2023-01-16 17:10

:bust_in_silhouette: Reply From: Wakatta

Double tap, Longpress unfortunately these concepts do not exist in InputEvent

There is an option in project settings that lets you emulate ScreenTouch as mouse events, you’ll be wanting to enable that.

The preferably have an autoload to pool unhandled events

func _unhandled_input(event):
    var new_event
    if event is InputEventScreenTouch:
        if event.pressed:
            new_event = InputEventMouseMotion.new()
            new_event.position = event.position

    Input.parse_event(new_event)

As mentioned before the other conditions do not exist and you will have to code it on your lonesome