Program can press key

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.

Hi @ctremblay,

take a look here for automatically control of mouse and keyboard events with java.
Java Robot - Javatpoint

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

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.