# Backspace in HTML5

**URL:** <https://forum.defold.com/t/backspace-in-html5/44768>\
**Category:** Bugs\
**Created:** [February 27, 2019, 2:17pm UTC](https://forum.defold.com/t/backspace-in-html5/44768 "2019-02-27T14:17:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rytis](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rytis/32/13908_2.png) [@Rytis](https://forum.defold.com/u/Rytis)\
**Post date:** [February 27, 2019, 2:17pm UTC](https://forum.defold.com/t/backspace-in-html5/44768/1 "2019-02-27T14:17:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wistpotion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/wistpotion/32/29771_2.png) [@Wistpotion](https://forum.defold.com/u/Wistpotion)\
**Post date:** [March 9, 2024, 8:22pm UTC](https://forum.defold.com/t/backspace-in-html5/44768/2 "2024-03-09T20:22:12Z")

</div>

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:

```html
<!-- 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:

```lua
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.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [March 10, 2024, 12:54pm UTC](https://forum.defold.com/t/backspace-in-html5/44768/3 "2024-03-10T12:54:52Z")

</div>

> [@Wistpotion](#):
>
> This issue still exist and applies to enter as well

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

---

<div class="post-metadata">

**Author:** ![Wistpotion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/wistpotion/32/29771_2.png) [@Wistpotion](https://forum.defold.com/u/Wistpotion)\
**Post date:** [March 10, 2024, 1:18pm UTC](https://forum.defold.com/t/backspace-in-html5/44768/4 "2024-03-10T13:18:08Z")

</div>

Submitted now!
