The program that comes closest to this that I know of is XMacro:
The XMacro package contains two simple, C++ programs (xmacrorec and xmacroplay) for recording and replaying keyboard and mouse events on an X server.
This is available in the Ubuntu repository as the xmacro package.