Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
p5.js ReferenceError: keyDown is not defined

Created this simple code that should move a rect in p5.js. I get the error ReferenceError: keyDown is not defined. What's wrong? Do I have to install any other libraries or is it a syntax error?

function setup() {
    createCanvas(400, 400);
}
 
let x = 0;
let y = 0;

function draw() {
    if (keyDown(68)) // d
    {
        x += 3
    }
    if (keyDown(65)) // a 
    {
        x -= 3
    }
    if (keyDown(87)) 
    {
        y -= 3
    }
    if (keyDown(83)) 
    {
        y += 3
    }

    background(220)
    rect(x, y, 30, 50);
           
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Syntax error. The correct way to check for a keypress is KeyIsDown(keycode):

function setup() {
    createCanvas(400, 400);
}
 
let x = 0;
let y = 0;

function draw() {
    if (keyIsDown(68)) // d
    {
        x += 3
    }
    if (keyIsDown(65)) // a 
    {
        x -= 3
    }
    if (keyIsDown(87)) 
    {
        y -= 3
    }
    if (keyIsDown(83)) 
    {
        y += 3
    }

    background(220)
    rect(x, y, 30, 50);
           
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Solved by @Matei Piele with keyIsDown(), posting this so other people know, can also be solved with keyIsPressed().

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda