# Command: MouseXSpeed()

MouseXSpeed() Definition:

Returns the changes in the mouse location since the LAST call to the command

Parameter Description:

None.

Command Description:

Often you'd like to find the difference between where the mouse WAS to where it is NOW. You can use this command and MouseYSpeed() in pairs to find out the changes in the mouse location between calls.
You really have to use these commands TWICE to get anything out of them. Each call you make returns the difference in location since the LAST time you called it.
In the example, when you run it, move the mouse to a location, press left mouse button. This makes the first call. Then, move the mouse and press right mouse button. The second call will return the difference since the first call and display it for you.

Example:

; MouseXSpeed()/MouseYSpeed() examples
; Set graphics mode and double buffering
Graphics 800,600,16
SetBuffer BackBuffer()
; repeat until right mouse button is pressed
Repeat
Cls ; Clear screen
Rect MouseX(),MouseY(),2,2,1 ; draw a small box where the mouse is
; if user hits left mouse, take note of where it is and call mousexspeed/mouseyspeed
If MouseHit(1) Then startx=MouseXSpeed():starty=MouseYSpeed()
; When user hits right mouse button, record the difference between last call
; and this call to the mousey/xspeed commands.
If MouseHit(2) Then endx=MouseXSpeed():endy=MouseYSpeed()
Flip ; flip screen into view
Until endx ; end the loop when we have a value for endx
; display results
Text 0,0,"Changes in mouse coordinates: " + endx + "," + endy
Flip ; flip changes into view
; Wait for escape
While Not KeyHit(1)
Wend

Index