Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Posts
    4

    Unanswered: Mouse Pointer Location

    How can I determine the location of the mouse pointer without using the mouse move, up or down events. I am running through a loop and would like to know if the user has moved the mouse while the code is running.

  2. #2
    Join Date
    Dec 2001
    Posts
    79
    You can use the GetCursorPos API to retrieve the mouse position. Ex.:

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type


    sub a_test()
    Dim ptCursor As POINTAPI
    GetCursorPos ptCursor
    msgbox "xpos = " & ptCursor.X
    msgbox "ypos = " & ptCursor.Y
    exit sub

    Hope this helps,

    Peter De Baets
    Peter's Software - MS Access Tools for Developers
    http://www.peterssoftware.com
    Peter De Baets
    Peter's Software - Microsoft Access Tools for Developers
    http://www.peterssoftware.com

  3. #3
    Join Date
    Dec 2001
    Posts
    79
    oops!

    You also need the API declaration:

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Peter De Baets
    Peter's Software - Microsoft Access Tools for Developers
    http://www.peterssoftware.com

  4. #4
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    use an API call:
    at the top of your code, put
    Code:
    Option Explicit
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Dim point As POINTAPI
    Then, (since you're wanting to check if the user moved the mouse, i assume you're using the timer) in the Timer() Event of your form, put the following code:
    Code:
     Call GetCursorPos(point)
    
     'assuming you've put labels on your form to hold the results. 
     'if no labels, just assign .X and .Y to variables
     LabelX.Caption = point.X
     LabelY.Caption = point.Y
    don't forget to set the Form.TimerInterval = 1000 or whatever in the Form_Load().

    hope it helps.

  5. #5
    Join Date
    May 2004
    Posts
    4

    Smile Mouse code worked

    That did the trick,thanks

Posting Permissions

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