Set Mouse Position

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
wangbo_coldwind
Knows some wx things
Knows some wx things
Posts: 38
Joined: Thu Jun 09, 2005 1:44 am
Location: china

Set Mouse Position

Post by wangbo_coldwind » Wed Mar 15, 2006 2:31 am

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?

Thanks

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Wed Mar 15, 2006 6:30 am

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".

wangbo_coldwind
Knows some wx things
Knows some wx things
Posts: 38
Joined: Thu Jun 09, 2005 1:44 am
Location: china

Post by wangbo_coldwind » Wed Mar 15, 2006 6:37 am

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.

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Thu Mar 16, 2006 12:35 am

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).

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Mar 16, 2006 8:14 am

Hi!
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.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Post Reply