Results 1 to 5 of 5

Thread: Problems with a mouse API function...

  1. #1

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Question Problems with a mouse API function...

    I'm using this function I wrote:

    VB Code:
    1. Public Sub MoveMouse(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long)
    2.     'Rectangle
    3.     Dim mmRECT As RECT
    4.    
    5.     'Y increment
    6.     Dim XInc As Double
    7.     Dim YInc As Double
    8.     XInc = ((X2 - X1) / 10000)
    9.     YInc = ((Y2 - Y1) / 10000)
    10.    
    11.     'Set mouse cursor to hand
    12.     Screen.MousePointer = vbCustom
    13.     Screen.MouseIcon = LoadResPicture("POINT", vbResCursor)
    14.    
    15.     'Move mouse
    16.     Dim i As Double
    17.     For i = 0 To 10000
    18.         mmRECT.Top = Y1 + (YInc * i)
    19.         mmRECT.Bottom = Y1 + (YInc * i) + 1
    20.         mmRECT.Left = X1 + (XInc * i)
    21.         mmRECT.Right = X1 + (XInc * i) + 1
    22.         ClipCursor mmRECT
    23.         PauseMe 250
    24.     Next
    25.    
    26.     'Set cursor to default
    27.     Screen.MousePointer = vbDefault
    28.    
    29.     'Release mouse
    30.     ClipCursor &H0
    31. End Sub
    32.  
    33.  
    34. 'Pause system in a loop temporarily
    35. Public Sub PauseMe(lngPauseDuration As Long)
    36.     Dim i As Long
    37.     Do Until i = lngPauseDuration
    38.         i = i + 1
    39.         DoEvents
    40.      Loop
    41. End Sub

    To force the mouse to move (in a straight line) between two points. The PauseMe function just holds up the processor for a tiny period of time so visual effects can actually be seen (they're too fast otherwise).


    Anyway, this function works fine if the points are:
    X1 = 0
    Y1 = 0
    X2 = 12000
    Y2 = 12000

    (topleft->bottom right)

    but in reverse, nothing happens for awhile, and then some time later, the mouse moves as I want it to... it's really quite odd....
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  2. #2

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Hmmm more weirdness. In the first instance (top-left - bottom right), the cursor moves, but that loop isn't exited correctly... someone have a go and see what happens?

    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  3. #3

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Bugger it, it's right now.

    Here's a working sub to move the cursor between two points if anyone wants it.

    VB Code:
    1. 'Move mouse from x1/y1 to x2/y2
    2. Public Sub MoveMouse(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long)
    3.     'Rectangle
    4.     Dim mmRECT As RECT
    5.    
    6.     'Y increment
    7.     Dim XInc As Double
    8.     Dim YInc As Double
    9.     XInc = ((X2 - X1) / 1000)
    10.     YInc = ((Y2 - Y1) / 1000)
    11.    
    12.     'Set mouse cursor to hand
    13.     Screen.MousePointer = vbCustom
    14.     Screen.MouseIcon = LoadResPicture("POINT", vbResCursor)
    15.    
    16.     'Move mouse
    17.     Dim i As Double
    18.     Open "./test.txt" For Output As #1
    19.     For i = 0 To 1000
    20.         mmRECT.Top = Y1 + (YInc * i)
    21.         mmRECT.Bottom = Y1 + (YInc * i) + 1
    22.         mmRECT.Left = X1 + (XInc * i)
    23.         mmRECT.Right = X1 + (XInc * i) + 1
    24.         ClipCursor mmRECT
    25.         PauseMe 250
    26.     Next
    27.  
    28.     'Set cursor to default
    29.     Screen.MousePointer = vbDefault
    30.    
    31.     'Release mouse
    32.     ClipCursor &H0
    33. End Sub
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Thanks rjlohan
    -= a peet post =-

  5. #5

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    I'm sure you'll find a use for it somewhere....



    Note: There is an API - SetCursorPos which can cut this code down considerably, but my way locks the mouse, so the user can't move it - much nicer visually.

    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width