Getting response from pressing different keys

Hi there. I have a wonderful and curious student who is working on a side project, attempting to make a digital piano. Her hopes is that by pressing different letter keys on the keyboard, her app. would respond with the sound from that piano key. I’m not well versed in how to make that happen, and was hoping for any suggestions and/or examples on how to move her forward in the project. I appreciate any insights.

LINK TO CURRENT PROJECT
LINK TO EXISTING APP THAT’S BEING USED AS A REFERENCE

Thanks so much.

Garrett

Use a keydown event for the screen element and add e as a parameter. Then, use e.key and a switch/case to determine what happens when each key is pressed.

onEvent("keyboard", "keydown", function (e) {
  switch (e.key) {
    case "q":
      playSound("key07.mp3");
      break;
    case "w":
      playSound("key08.mp3");
      break;
    // keep doing that for every key
    // uppercase keys are just the uppercase letter, like Q
  }
});