# Function KeyPressed

**URL:** <https://discourse.processing.org/t/function-keypressed/7676>\
**Category:** Beginners\
**Created:** [January 20, 2019, 2:19pm UTC](https://discourse.processing.org/t/function-keypressed/7676 "2019-01-20T14:19:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Awazez](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Awazez](https://discourse.processing.org/u/Awazez)\
**Post date:** [January 20, 2019, 2:19pm UTC](https://discourse.processing.org/t/function-keypressed/7676/1 "2019-01-20T14:19:42Z")

</div>

Hi !  
I’m quite new in javascript and I tried to program a Flappy bird with the coding train video.  
I did a function named KeyPressed

```auto
function KeyPressed () {
  if (key == "") {
    console.log("SPACE");
  }
}

```

But it’s not working and I don’t see anything appear when I press space in the console. Can you help me with it ? Thanks !

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 20, 2019, 2:24pm UTC](https://discourse.processing.org/t/function-keypressed/7676/2 "2019-01-20T14:24:56Z")

</div>

> [@Awazez](#):
>
> `if (key == "") {`

`""` is an empty String. Use `" "` (or `' '`) instead for the space character. 😉

P.S.: Edit & format your posted code. 🗒

---

<div class="post-metadata">

**Author:** ![Awazez](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Awazez](https://discourse.processing.org/u/Awazez)\
**Post date:** [January 20, 2019, 2:33pm UTC](https://discourse.processing.org/t/function-keypressed/7676/3 "2019-01-20T14:33:31Z")

</div>

Yeah ! It’s working. Thanks a lot !

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 20, 2019, 2:37pm UTC](https://discourse.processing.org/t/function-keypressed/7676/4 "2019-01-20T14:37:36Z")

</div>

> [@Awazez](#):
>
> KeyPressed ()

also it should be

```auto
function setup() {

}

function draw() {
  
}

function keyPressed() {
  print("keyPressed "+key+" keyCode "+keyCode);
  if ( key == ' ' ) console.log("[space]"); 
}

```

and we see it ?  
in browser / inspect / Console

 ![2019-01-20_21-36-50_snap](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/724dbcdb7f2c24c7227bc032b8bd5fd83b0dc27d.png)

---

<div class="post-metadata">

**Author:** ![Awazez](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Awazez](https://discourse.processing.org/u/Awazez)\
**Post date:** [January 20, 2019, 2:40pm UTC](https://discourse.processing.org/t/function-keypressed/7676/5 "2019-01-20T14:40:54Z")

</div>

Thanks a lot for the fast answer !
