A Number system variable that contains the code of the last key typed.
All keys have a keyCode. For example, the a key has the keyCode 65. The keyCode variable is helpful for checking whether a special key has been typed. For example, the following conditional checks whether the enter key has been typed:
if (keyCode === 13) {
// Code to run if the enter key was pressed.
}
The same code can be written more clearly using the system variable ENTER which has a value of 13:
if (keyCode === ENTER) {
// Code to run if the enter key was pressed.
}
The system variables BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, and RIGHT_ARROW are all helpful shorthands the key codes of special keys. Key codes can be found on websites such as keycode.info.
Ejemplos
Referencias Relacionadas
key
Una variable del sistema String que contiene el valor de la última tecla pulsada.
keyCode
Una variable de sistema Number que contiene el código de la última tecla presionada.
keyIsDown
Devuelve true si la tecla que se está comprobando está presionada y false si no lo está.
keyIsPressed
Una variable de sistema Boolean que es true si se está presionando alguna tecla y false si no se está presionando ninguna tecla.