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

91
Vistas
p5.js sound and keyTyped or keyPressed function

I’m trying to write a code where when I press a certain keyboard key, a sound will play. I’m using p5.js and have tried the keyTyped() function and keyPressed() function but it’s not working. By not working, I meant there is nothing wrong with the code that I’ve typed because it can be played but no sound is produced when i click on the A key. The code I used Function keyTyped () {

if ( key === ‘a’) {

keyA.play ( ) }

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The following works on my system. Make sure that you have a folder called 'assets' and that you have dragNdropped a file called 'keyA.mp3' into it. I used a Chrome browser on a Mac. Important: click on the gray window first, then type 'a' from your keyboard and it should work.

function preload(){
  sound = loadSound('assets/keyA.mp3');
}

function draw() {
createCanvas(displayWidth, displayHeight);
background(209);
}

function keyTyped() {
  if (key == 'a') {
    sound.play();
  } 
}
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