See MouseInfo API (and indirectly, PointerInfo API) to get the mouse's current location.
See Java Robot API to control the mouse/keyboard.