Skip to content

Instantly share code, notes, and snippets.

@Saccarab
Last active February 24, 2019 14:13
Show Gist options
  • Save Saccarab/08561776e2360a63daf63966d9848738 to your computer and use it in GitHub Desktop.
Save Saccarab/08561776e2360a63daf63966d9848738 to your computer and use it in GitHub Desktop.
Check if a pressed key changes a text editor state
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