# Program can press key

**URL:** <https://discourse.processing.org/t/program-can-press-key/42604>\
**Category:** Project Guidance\
**Created:** [August 17, 2023, 10:04am UTC](https://discourse.processing.org/t/program-can-press-key/42604 "2023-08-17T10:04:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctremblay](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@ctremblay](https://discourse.processing.org/u/ctremblay)\
**Post date:** [August 17, 2023, 10:04am UTC](https://discourse.processing.org/t/program-can-press-key/42604/1 "2023-08-17T10:04:54Z")

</div>

I’m playing a game and had the idea it be fun to make an ai play it, but how do I get it where the ai i create can make the computer think it pressed a key. I dont wanna place the ai in the game or remake the game. I want to have my ai in 1 window & it deciding on how to play.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [August 17, 2023, 2:18pm UTC](https://discourse.processing.org/t/program-can-press-key/42604/2 "2023-08-17T14:18:20Z")

</div>

Hi @ctremblay,

take a look here for automatically control of mouse and keyboard events with java.  
[Java Robot - Javatpoint](https://www.javatpoint.com/java-robot)

Nevertheless, if you want to implement an ai, resp. train a model, you need also be able to fetch the stats of playing, or detect the state of the current program flow (ie needs restart, stuck, etc.)

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![ctremblay](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@ctremblay](https://discourse.processing.org/u/ctremblay)\
**Post date:** [August 17, 2023, 2:39pm UTC](https://discourse.processing.org/t/program-can-press-key/42604/3 "2023-08-17T14:39:16Z")

</div>

I know how to make an ai but so far all my ai can do is effect the stuff in the program its in. I want the ai to make my computer think a button is pressed so another program can be altered.
