Returns true if the key it’s checking is pressed and false if not.
keyIsDown() is helpful when checking for multiple different key presses. For example, keyIsDown() can be used to check if both LEFT_ARROW and UP_ARROW are pressed:
if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
// Move diagonally.
}keyIsDown() can check for key presses using strings based on KeyboardEvent.key or KeyboardEvent.code values, such as keyIsDown('x') or keyIsDown('ArrowLeft').
Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported. This is a breaking change from previous versions.
You can still use the p5 constants like LEFT_ARROW which now map to string values internally rather than numeric codes.
Ejemplos
Sintaxis
keyIsDown(code)
Parámetros
Returns
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.