# Function KeyTyped () and draw function

**URL:** <https://discourse.processing.org/t/function-keytyped-and-draw-function/36633>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 28, 2022, 2:33pm UTC](https://discourse.processing.org/t/function-keytyped-and-draw-function/36633 "2022-04-28T14:33:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JessJess](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@JessJess](https://discourse.processing.org/u/JessJess)\
**Post date:** [April 28, 2022, 2:33pm UTC](https://discourse.processing.org/t/function-keytyped-and-draw-function/36633/1 "2022-04-28T14:33:57Z")

</div>

Hi, I want to create a code where when I click a key on the keyboard it will play music and draw a rectangle. I have managed to add music using the keyTyped() function but I am not sure how to add a rectangle to the canvas.  
Thank you

---

<div class="post-metadata">

**Author:** ![PhySan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/physan/32/16087_2.png) [@PhySan](https://discourse.processing.org/u/PhySan)\
**Post date:** [April 28, 2022, 7:16pm UTC](https://discourse.processing.org/t/function-keytyped-and-draw-function/36633/2 "2022-04-28T19:16:17Z")

</div>

I @JessJess

The following link might help you:

> **[Reference](https://processing.org/reference/rect_.html)**
>
> Draws a rectangle to the screen. A rectangle is a four-sided shape with every angle at ninety degrees. By default, the first two parameters set the location of the upper-left corner, the third sets th…

Hope it helps! 🙂
