A Number system variable that contains the code of the last key pressed.
Every key has a numeric key code. For example, the letter a key has the key code 65. Use this key code to determine which key was pressed by comparing it to the numeric value of the desired key.
For example, to detect when the Enter key is pressed:
if (keyCode === 13) { // Enter key
// Code to run if the Enter key was pressed.
}Alternatively, you can use the key function to directly compare the key value:
if (key === 'Enter') { // Enter key
// Code to run if the Enter key was pressed.
}Use the following numeric codes for the arrow keys:
Up Arrow: 38 Down Arrow: 40 Left Arrow: 37 Right Arrow: 39
More key codes can be found at 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.