If you want to generate mouse and keyboard events from a program in the background, you can use the uinput virtual device driver. First make sure that the driver is loaded by checking to see if the /dev/input/uinput file exists. If it doesn't, load the module with
Code:
sudo modprode uinput
You can generate input events by writing to this file. A good reference for this can by found in the wminput project that allows the wiimote to be used as an input device in linux. Here is a link to the most relevant file in that project:
http://abstrakraft.org/cwiid/browser...input/uinput.c
As for reading the screen, the X windows system provides functionality to obtain a dump of any of the windows under its control, including the root window. Look at the documentation of the XGetImage() function in Xlib.