You could use library in this article:
Global Mouse and Keyboard Library
For tracking and repalying mouse position I would use timer with interval of 50ms or something. In each tick current position is stored in a list. To replay movement another timer is started with same interval which gets next position from list and sets it as current mouse position(using library above)