The XMacro package contains two simple, C++ programs (xmacrorec and xmacroplay) for recording and replaying keyboard and mouse events on an X server. This functionality is achieved through the XTest extension. The programs are heavily based on the xremote utility of Jan Ekholm (chakie at infa.abo.fi).

xmacrorec:
Grabs all the control over your local display and send the mouse and keyboard events to the remote display. In the meantime it emits KeyStrPress, KeyStrRelease, ButtonPress and ButtonRelease lines to the standard output. It emits MotionNotify lines only if the event struct of the above four events contains different coordinates than the previous event or a mouse button is pressed during the movement.

xmacroplay can be used to playback recorded events or send any other mouse/keyboard events you choose. It is very handy for scripting an X display - for example running some smoke tests on the GUI application.Xmacro Installation:
Open the terminal and type following command to install Xmacro:

sudo apt-get install xmacro

Using Xmacro:
The first thing you need to do is to record the events (mouse movements and keystroke) and for this you need to use xmacrorec2 package of Xmacro, open the terminal and type following command to record and store these events in a text file:

xmacrorec2 > nikesh.txt

This will bring up a prompt (as shown below) where you need to input any keystroke to tell xmacrorec2 to "stop" the record.

Note: As xmacrorec doesn't save the timestamps of the event, you may need to insert Delay statements into the recorded file!

Once record is done and store in the txt file (nikesh.txt) you can re-plan the recorded session using following command, open the terminal and type following command:

xmacroplay "$DISPLAY" < nikesh.txt

The "$DISPLAY" argument just tells xmacro to use your current display.