Skip to content

Instantly share code, notes, and snippets.

@rinsuki
Created April 6, 2025 00:50
Show Gist options
  • Save rinsuki/90186619f3566e58cfa492a2d950b555 to your computer and use it in GitHub Desktop.
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
(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