Last active
February 24, 2019 14:13
-
-
Save Saccarab/08561776e2360a63daf63966d9848738 to your computer and use it in GitHub Desktop.
Check if a pressed key changes a text editor state
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
function (keycode) { | |
//event key code list | |
const valid = | |
(keycode > 47 && keycode < 58) || // number keys | |
keycode == 32 || keycode == 13 || // spacebar & return key(s) (if you want to allow carriage returns) | |
keycode == 8 || keycode == 46 || // delete keys | |
(keycode > 64 && keycode < 91) || // letter keys | |
(keycode > 95 && keycode < 112) || // numpad keys | |
(keycode > 185 && keycode < 193) || // ;=,-./` (in order) | |
(keycode > 218 && keycode < 223); // [\]' (in order) | |
return valid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment