in reply to Send a keyboard input to a process

Almost. You can send messages to windows, and windows are associated with pids. See X11::GUITest, Re^2: How to Retrieve another Process' Window Title?