# Getting response from pressing different keys

**URL:** <https://forum.code.org/t/getting-response-from-pressing-different-keys/37130>\
**Category:** Coding and Debugging Help\
**Created:** [October 26, 2022, 10:43pm UTC](https://forum.code.org/t/getting-response-from-pressing-different-keys/37130 "2022-10-26T22:43:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gince](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@gince](https://forum.code.org/u/gince)\
**Post date:** [October 26, 2022, 10:43pm UTC](https://forum.code.org/t/getting-response-from-pressing-different-keys/37130/1 "2022-10-26T22:43:48Z")

</div>

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](https://studio.code.org/projects/applab/_67nmaGmd1cuAZ4c8beIbKE3Ztdw7OKP3govSEoEgfc)  
[LINK TO EXISTING APP THAT’S BEING USED AS A REFERENCE](https://studio.code.org/projects/applab/7dwrTW0zv_u4K9OF7zWEYB3iuHJnr5qR3jYH1tZrk44/)

Thanks so much.

Garrett

---

<div class="post-metadata">

**Author:** ![wutadam](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/wutadam/32/7711_2.png) [@wutadam](https://forum.code.org/u/wutadam)\
**Post date:** [October 27, 2022, 1:50am UTC](https://forum.code.org/t/getting-response-from-pressing-different-keys/37130/2 "2022-10-27T01:50:47Z")

</div>

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.

```javascript
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
  }
});
```
