CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Mouse Movement

  1. #1
    Join Date
    Jan 2000
    Posts
    45

    Mouse Movement

    How do i move the mouse on the screen?


  2. #2
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Re: Mouse Movement

    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



  3. #3
    Join Date
    Dec 1999
    Posts
    128

    Re: Mouse Movement

    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?

    -------------------------
    Nick A.

  4. #4
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Mouse Movement

    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
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  5. #5
    Join Date
    Dec 1999
    Posts
    128

    Re: Mouse Movement

    Great. That's what i needed. Thanx a lot.

    -------------------------
    Nick A.

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

Featured