Trying To Get Touch Working On Android Mobile Chrome With Standard Desktop HTML5 Build / Function & QR Code Provided

Godot Version

v4.6.1.stable.official [14d19694e] Linux x86_64 (CachyOS KDE Plasma)

Question

Hi,

Trying to make touch work on Android mobile Chrome browser, but it’s not working well.
We are running the standard desktop HTML5 build on a Samsung S23 Ultra smartphone.

It sorta works, but not really well…
We think touch works, but drag touch is not functional at this time?
Please look over our source below and provide a solution:
(we are doing something wrong for sure)

QR Code below to play current version on the Android OS phone:
(it is on Itch Indie distribution site)

func _input(event):
var touchDetected = false

InputDetected = false

KeyboardSpacebarPressed = false
KeyboardEnterPressed = false
KeyboardBackspacePressed = false

KeyTypedOnKeyboard = "`"

if ScreensCore.ScreenFadeStatus != ScreensCore.FadingIdle:  return

MouseButtonLeftPressed = false
if (InputCore.DelayAllUserInput > -1):  return

if event is InputEventKey:
	InputDetected = true
	if event.keycode == KEY_ESCAPE and event.pressed:
		if (ScreensCore.ScreenToDisplay < ScreensCore.TitleScreen):  AudioCore.PlayEffect(1)
		ScreensCore.ScreenToDisplayNext = ScreensCore.TitleScreen
		ScreensCore.ScreenFadeStatus = ScreensCore.FadingToBlack
		LogicCore.StillPlaying = false
		LogicCore.GameQuit = true
		LogicCore.GameOver = true
		InputCore.MouseButtonLeftPressed = false
		InputCore.DelayAllUserInput = 35
		AudioCore.PlayMusic(0, true)
	elif event.keycode == KEY_SPACE and event.pressed:
		if (ScreensCore.ScreenToDisplay < ScreensCore.TitleScreen):  AudioCore.PlayEffect(1)
		KeyboardSpacebarPressed = true
		KeyTypedOnKeyboard = "_"
	elif event.keycode == KEY_ENTER and event.pressed:
		if (ScreensCore.ScreenToDisplay < ScreensCore.TitleScreen):  AudioCore.PlayEffect(1)
		KeyboardEnterPressed = true
	elif event.keycode == KEY_BACKSPACE and event.pressed:
		KeyboardBackspacePressed = true

	if (event.pressed && event.keycode != KEY_SHIFT):
		if (event.unicode > 32 && event.unicode < 137):
			KeyTypedOnKeyboard = char(event.unicode)

if (event is InputEventScreenDrag and event.index > 0):
	MouseButtonLeftPressed = true
	MouseScreenX = event.position.x
	MouseScreenY = event.position.y
	touchDetected = true

if (event is InputEventScreenTouch and event.is_pressed() == true):
	MouseButtonLeftPressed = true
	MouseScreenX = event.position.x
	MouseScreenY = event.position.y
	touchDetected = true

if (touchDetected == false):
	if event is InputEventMouseMotion:
		MouseScreenX = event.position.x
		MouseScreenY = event.position.y

	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT:
			if (event.is_pressed() == true):
				MouseButtonLeftPressed = true
				MouseScreenX = event.position.x
				MouseScreenY = event.position.y

				InputThatStartedNewGame = InputKeyboard
			elif (event.is_released() == true):
				MouseButtonLeftPressed = false

	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_RIGHT:
			if (event.is_pressed() == true):
				MouseButtonRightPressed = true

				InputThatStartedNewGame = InputKeyboard
			else:
				MouseButtonRightPressed = false

if (JoystickDirection[InputKeyboard] != JoyCentered or JoyButtonOne[InputKeyboard] != NotPressed or JoyButtonTwo[InputKeyboard] != NotPressed or MouseButtonLeftPressed != false or MouseButtonRightPressed != false):
	InputDetected = true

pass

We got it working, thanks…

if (event is InputEventScreenTouch and event.is_pressed() == true):
MouseButtonLeftPressed = true
MouseScreenX = event.position.x
MouseScreenY = event.position.y
touchDetected = true
elif (event is InputEventScreenDrag):
MouseButtonLeftPressed = true
MouseScreenX = event.position.x
MouseScreenY = event.position.y
touchDetected = true

1 Like