# How to make processing press a key

**URL:** <https://discourse.processing.org/t/how-to-make-processing-press-a-key/8422>\
**Category:** Coding Questions\
**Created:** [February 15, 2019, 3:54pm UTC](https://discourse.processing.org/t/how-to-make-processing-press-a-key/8422 "2019-02-15T15:54:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Supercube9307](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Supercube9307](https://discourse.processing.org/u/Supercube9307)\
**Post date:** [February 15, 2019, 3:54pm UTC](https://discourse.processing.org/t/how-to-make-processing-press-a-key/8422/1 "2019-02-15T15:54:03Z")

</div>

Hi all, I have had this question for a long time: Is there any way to make processing act as if the user pressed a key?

Ex: When a condition is true, the script would send a signal to the computer that the “P” key had just been pressed on the keyboard, and the computer would react accordingly.

Any and all advice appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [February 15, 2019, 4:34pm UTC](https://discourse.processing.org/t/how-to-make-processing-press-a-key/8422/2 "2019-02-15T16:34:36Z")

</div>

You could trigger the code yourself, something like:

```auto
void keyPressed(){
  if(key == 'p'){
    myFunction();
  }
}

void mousePressed(){
  myFunction();
}

```

This code calls the `myFunction()` function when the user presses `P` or presses the mouse. The computer doesn’t really need to know the difference.

You could also look into the `Robot` class in Java, which can generate mouse and keyboard events.
