Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!