Keystroke simulator
Quoted 3 lines · Mister Google
Is there a way to simulate a keystroke to a program, ie. have a program send it something so that as far as it's concerned, say, the "P" key has been pressed?
Yes. That's what programs like telnetd do.
Look for man 4 pts.