Page 1 of 1

Set Mouse Position

Posted: Wed Mar 15, 2006 2:31 am
by wangbo_coldwind
Hi,I see there is a wxGetMousePosition function to get the mouse's position,Is there a wxSetMousePosition to move the mouse to the appointed position?


Posted: Wed Mar 15, 2006 6:30 am
by eco
Use wxWindow::WarpPointer. Note, you can't do this on Mac because, as the documentation says: "Apple Human Interface Guidelines forbid moving the mouse cursor programmatically".

Posted: Wed Mar 15, 2006 6:37 am
by wangbo_coldwind
Can WrapPoint move the mouse in the screen, What I wanted is not just move, but drag. and not in the program itself, but on another program. For example, I want my program can click start->program->... in windows like i do it by myself.

Posted: Thu Mar 16, 2006 12:35 am
by eco
You could fake motion just fine. Technically, the windowing environment just adds the mouse motion vector to the current mouse position rapidly to simulate motion and you could do the same (wxIdleEvent may be a starting point for this) although the user could "fight" you over the position which would look odd (it'd flicker back and forth) but I'm not aware of the ability to simulate clicks of any sort. I'd suggest looking up the relevant Win32 API calls if you what to pull of what you are saying (if anyone else out there in the forumn knows of a way to do this with just wxWidgets, feel free to share).

Posted: Thu Mar 16, 2006 8:14 am
by upCASE
Technically this is possible. The problem is that you'll have to device your own way to do that for each platform. Moving the mouse can be done, as eco said, by using WarpPointer().

For virtually clicking the mouse wxWidgets offers no way to do that. On Windows you can do that by either using the old mouse_event() function, or the newer SendInput(). I'm not sure how other platforms handle this or if it is even possible.