Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda