Click to See Complete Forum and Search --> : Mouse Movement


Starcraft
January 16th, 2000, 07:07 PM
How do i move the mouse on the screen?

Rippin
January 18th, 2000, 05:33 PM
Well, you take the mouse in either your right or left hand AND.....(drum-roll please)...you move your hand and the mouse moves on the screen. WOW!!! Just joking. Use the SetCursorPos API function.


private Declare Function SetCursorPos Lib _
"user32" (byval X as Long, byval Y as Long) _
as Long




Then just call it like so:

Call SetCursorPos(20,20)




The above line will move the mouse to the 20th pixel from the left of the screen and to the 20th pixel from the top of the screen.

Hope this helps,
Rippin

Nick A.
January 19th, 2000, 08:12 AM
Nice. Do you by any chance know how to hide the cursor? Also, how can you restrict its movement within a certain area of a window?

Aaron Young
January 19th, 2000, 08:23 AM
You can use the ClipCursor and ShowCursor APIs, ie.

private Type RECT
Left as Long
Top as Long
Right as Long
Bottom as Long
End Type

private Declare Function ClipCursor Lib "user32" (lpRect as Any) as Long
private Declare Function ShowCursor Lib "user32" (byval bShow as Long) as Long
private Declare Function GetWindowRect Lib "user32" (byval hwnd as Long, lpRect as RECT) as Long

private Sub Command1_Click()
static bRestricted as Boolean
Dim tRECT as RECT

bRestricted = Not bRestricted
If bRestricted then
'Restrict the Cursor to Inside the Form Area
Call GetWindowRect(hwnd, tRECT)
Call ClipCursor(tRECT)
else
'Release the Cursor
Call ClipCursor(byval 0&)
End If
End Sub

private Sub Command2_Click()
static bHide as Boolean
bHide = Not bHide
Call ShowCursor(Abs(Not bHide))
End Sub




Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com

Nick A.
January 19th, 2000, 08:35 AM
Great. That's what i needed. Thanx a lot.