Just use SetCursorPos API...
If the window isnt in ForeGround then dont set mouse pos. Not that hard?
Wheres the problem here?