MoveMouse x,y
Parameters
|
x - horizontal position to move the pointer to, in display coordinates y - vertical position to move the pointer to, in display coordinates |
Description
|
Warps the mouse pointer to a position in your display. The coordinates are the same ones MouseX and MouseY report, so 0,0 is the top-left of your window or screen and GraphicsWidth()-1,GraphicsHeight()-1 is the bottom-right corner. The command works out where that is on the desktop for you. Its main job is mouse-look. A first-person camera reads MouseXSpeed and MouseYSpeed each frame and then warps the pointer back to the centre of the screen, so the player can keep turning forever without the pointer hitting the edge of the desk. Hide it first with HidePointer and the recentring is invisible. It is also useful for putting the pointer where the player will need it: on the default button of a dialog, on the player's ship when a level starts, or back where it was before a menu took over. Helpfully, MoveMouse updates the internal reference point used by the speed commands at the same time, so recentring the pointer does not show up as a huge fake movement on the next MouseXSpeed call. It also updates the position immediately, so MouseX and MouseY read the new spot straight away. Gotcha: this moves the real system pointer, so it will yank the cursor away from whatever else the player was doing. Only warp while your window has the focus, and do not warp every frame unless you are actually in mouse-look mode. See also: MouseX, MouseY, MouseXSpeed, MouseYSpeed, HidePointer, ShowPointer. |
Example
; MoveMouse Example ; ----------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Varied warp positions each run SeedRnd MilliSecs() While Not KeyDown(1) Cls ; MoveMouse teleports the pointer to the given screen position - ; MouseX/MouseY immediately report the new location. If KeyHit(57) Then MoveMouse Rand(20,619),Rand(60,459) ; Space: random warp If MouseHit(1) Then MoveMouse 320,240 ; left click: re-centre ; Centre marker (the re-centre target) Color 90,90,90 Line 310,240,330,240 Line 320,230,320,250 ; Marker at the (possibly warped) pointer position Color 255,255,0 Oval MouseX()-6,MouseY()-6,12,12,False Color 255,255,255 Text 0,0,"Space: warp pointer to a random spot Left click: MoveMouse 320,240 Esc: exit" Text 0,20,"MouseX()="+MouseX()+" MouseY()="+MouseY() Flip Wend End
Index