Skip to content

Instantly share code, notes, and snippets.

@luizbills
Last active August 6, 2025 23:48
Show Gist options
  • Select an option

  • Save luizbills/7ab0830985bfa1544a46a574a98e1762 to your computer and use it in GitHub Desktop.

Select an option

Save luizbills/7ab0830985bfa1544a46a574a98e1762 to your computer and use it in GitHub Desktop.
Handle keyboard events in mobile devices (only tested on Android)
let str = ""
litecanvas()
// create a invisible input
const input = document.createElement("input")
document.body.append(input)
input.style.cssText = "position:absolute;transform:translate(-99999px,-99999px)"
function tapped(tapx, tapy) {
// focus that input when the canvas is touched
input.focus()
}
function update() {
let char = lastkey()
if (iskeypressed(char) || iskeydown(char)) {
str = input.value
}
}
function draw() {
cls(0)
text(8, 8, str ? str : "type something", str ? 3 : 2)
}
@luizbills
Copy link
Author

luizbills commented Aug 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment