Last active
August 6, 2025 23:48
-
-
Save luizbills/7ab0830985bfa1544a46a574a98e1762 to your computer and use it in GitHub Desktop.
Handle keyboard events in mobile devices (only tested on Android)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live Demo