Created
April 6, 2025 00:50
-
-
Save rinsuki/90186619f3566e58cfa492a2d950b555 to your computer and use it in GitHub Desktop.
very wip, but you should be able to use this w/ ESM version of noVNC which `rfb` is not available on browser console. YOU NEED TO SET REMOTE MACHINE'S KEYBOARD LAYOUT TO US ONE
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
(async () => { | |
async function inputToCanvas(input) { | |
const needShift = '!"#$%&()}*+:>?@^_{|}~' | |
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | |
const canvas = document.querySelector("#screen canvas") | |
for (const char of input) { | |
console.log(char) | |
if (char === "\n") { | |
const keydown = new KeyboardEvent("keydown", { | |
code: "Enter", | |
key: "Enter", | |
}) | |
canvas.dispatchEvent(keydown) | |
await sleep(50) | |
continue | |
} | |
if (needShift.includes(char)) { | |
const keydown = new KeyboardEvent("keydown", { | |
code: "ShiftLeft", | |
key: "Shift", | |
shiftKey: true, | |
}) | |
canvas.dispatchEvent(keydown) | |
await sleep(25) | |
} | |
const keydown = new KeyboardEvent("keydown", { | |
code: "Unidentified", | |
key: char, | |
shiftKey: true, | |
}) | |
canvas.dispatchEvent(keydown) | |
await sleep(50) | |
if (needShift.includes(char)) { | |
const keydown = new KeyboardEvent("keyup", { | |
code: "ShiftLeft", | |
key: "Shift", | |
shiftKey: false, | |
}) | |
canvas.dispatchEvent(keydown) | |
await sleep(25) | |
} | |
} | |
} | |
inputToCanvas("echo Hello\n") | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment