# keyPressed(event) usage

**URL:** https://discourse.processing.org/t/keypressed-event-usage/32847
**Category:** Beginners
**Created:** [October 15, 2021, 9:41am UTC](https://discourse.processing.org/t/keypressed-event-usage/32847 "2021-10-15T09:41:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mhamilt](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@mhamilt](https://discourse.processing.org/u/mhamilt)
#### Post date: [October 15, 2021, 9:41am UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/1 "2021-10-15T09:41:09Z")

</div>

In the [`keyPressed` documentation](https://processing.org/reference/keyPressed_.html) one of the usages listed under Syntax is `keyPressed(event)`.

My expectation is that you could write the function as `keyPressed(Event event)`, but that doesn’t seem to be correct.

I anyone able to clear up what the docs are driving at and example of this kind of usage?

Ditto for [`mouseClicked`](https://processing.org/reference/mouseClicked_.html) or any function in the format `function(event)` in the documentation.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 15, 2021, 12:33pm UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/2 "2021-10-15T12:33:43Z")

</div>

it’s pretty much like in the examples on the pages you were referring to

```auto
void keyPressed() {
  if (key == '0') {
    value = 255;
  }
}

```

and

```auto
void mouseClicked() {
  if (value == 0) {
    value = 255;
  } else {
    value = 0;
  }
}

```

---

<div class="post-metadata">

### Author: ![mhamilt](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@mhamilt](https://discourse.processing.org/u/mhamilt)
#### Post date: [October 15, 2021, 12:59pm UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/3 "2021-10-15T12:59:32Z")

</div>

`keyPressed(event)` is highly suggestive that these functions pass an argument `event`

To clarify, what does `event` refer to in this context?

---

<div class="post-metadata">

### Author: ![BrendanL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/brendanl/32/14076_2.png) [@BrendanL](https://discourse.processing.org/u/BrendanL)
#### Post date: [October 15, 2021, 3:45pm UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/4 "2021-10-15T15:45:33Z")

</div>

I would guess a [KeyEvent](https://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyEvent.html) object from reading the Java documentation.

---

<div class="post-metadata">

### Author: ![mhamilt](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@mhamilt](https://discourse.processing.org/u/mhamilt)
#### Post date: [October 15, 2021, 4:25pm UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/5 "2021-10-15T16:25:23Z")

</div>

This checks out:

```java
void keyPressed(KeyEvent event) {
  println(event);  
}

```

Thank you.

What a weird way to convey that in the documentation. It seems odd not to include as KeyEvent has a couple of useful methods.

I’ll wing a pull request on the documentation with something a little more explanatory.

---

<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: [October 15, 2021, 5:54pm UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/6 "2021-10-15T17:54:41Z")

</div>

1. [PApplet](http://Processing.github.io/processing-javadocs/core/processing/core/PApplet.html#keyPressed-processing.event.KeyEvent-)
2. [KeyEvent](http://Processing.github.io/processing-javadocs/core/processing/event/KeyEvent.html)
3. [Event](http://Processing.github.io/processing-javadocs/core/processing/event/Event.html)

---

<div class="post-metadata">

### Author: ![mhamilt](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@mhamilt](https://discourse.processing.org/u/mhamilt)
#### Post date: [October 15, 2021, 6:20pm UTC](https://discourse.processing.org/t/keypressed-event-usage/32847/7 "2021-10-15T18:20:46Z")

</div>

Number 1 is the ticket.

Still a little too squirrelled away though.

Plus it doesn’t address the weird way of expressing the syntax
