Backspace in HTML5

Hello. I’m currently working on implementing a couple of input fields using dirtylarry. Everything seemed fine until I started testing my HTML5 build on mobile. For some reason, the backspace button on android keyboard behaves quite strange on HTML5. I’ve tried printing out every input action received. Usually, there is no action returned when I touch the backspace button. But if I hold it pressed for a while it from time to time it randomly returns a backspace action. Tested on a couple of android devices using firefox and got the same result.
I would assume there is something wrong with my setup if the backspace wasn’t working at all, but now I’m not sure why the backspace works so randomly.

2 Likes

This issue still exist and applies to enter as well. It sometimes catches the input, but it is very inconsistent and mostly doesn’t register. I’m testing on safari, on an iPhone 7 something. This would improve the experience for mobile web development if it was fixed.

My guess is that is an issue for keys that aren’t standard text / number input. Anything that wouldn’t appear in input.text really.

Until this gets resolved, here is the workaround I’m using:

This goes at the bottom of the html template:

<!-- horribly ugly workaround  -->
<script>
	let pressedKeys = {}

	document.getElementsByTagName("body")[0].addEventListener("keydown", function(ev) {
		pressedKeys[ev.code] = true
	})

	function CheckForKey(keycode) {
		//console.log(pressedKeys)

		if ( pressedKeys[keycode] ) {
			pressedKeys[keycode] = undefined
			return true
		}

		return false
	}
</script>

This is in a .script component:

function update(self, dt)
	if (html5) then
		local enter_pressed = html5.run([[CheckForKey("Enter")]])
		local backspace_pressed = html5.run([[CheckForKey("Backspace")]])

		if enter_pressed == "true" then
			--do stuff

		end
		if backspace_pressed == "true" then
			--do stuff

		end
	end
end

Works pretty well. My performance loving brain is very sad.

1 Like

I don’t think we have an issues reported for this. Would you mind opening one on GitHub?

1 Like

Submitted now!

1 Like