Last active
April 20, 2023 11:34
-
-
Save robinverona/5b036b8469a9726cfc0c1651ab0a503a to your computer and use it in GitHub Desktop.
Hijack keyboard layout in input
This file contains 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
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