Skip to content

Instantly share code, notes, and snippets.

@robinverona
Last active April 20, 2023 11:34
Show Gist options
  • Save robinverona/5b036b8469a9726cfc0c1651ab0a503a to your computer and use it in GitHub Desktop.
Save robinverona/5b036b8469a9726cfc0c1651ab0a503a to your computer and use it in GitHub Desktop.
Hijack keyboard layout in input
const azertyKeys = ['a', 'z', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'q', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'w', 'x', 'c', 'v', 'b', 'n']
const abcdKeys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
const textarea = document.getElementById('textarea') // just add example textarea in html file
azertyKeys.forEach((key, index) => {
textarea.addEventListener('keydown', e => {
if (e.key === key) {
e.preventDefault();
textarea.value += abcdKeys[index]
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment