Results 1 to 5 of 5

Thread: Get Mouse Click Positon

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    I need to get the current mouse position (using GetCursorPos API) for a mouse click event occurring at a different app than mine. I have tried the SetCapture but it goes away as soon as the other window is clicked.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You can use the GetAsyncKeyState API to detect a Mouse Click anywhere in the OS:

    Add a Timer Control to a Form and use this Code..
    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Sub Form_Load()
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Dim tPA As POINTAPI
        If GetAsyncKeyState(vbLeftButton) Then
            Call GetCursorPos(tPA)
            Caption = tPA.x & ":" & tPA.y
        End If
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    I have done it with the timer control, but want to do it without by detecting the mouse click event. Thanks

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The Only Way to Check the Mouse Click Event other than in a Timer Event using the GetAsyncKeyState API is to Check for the WM_RBUTTONDOWN Message, but as you cannot check Message Queues outsite your Thread, (i.e Other Apps), the Timer Control is your only viable solution.

    Someone feel free to correct me if I'm wrong.
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


    [This message has been edited by Aaron Young (edited 11-23-1999).]

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    Guess I was looking for a callback method. Been beating a bunch of options and have not been able to get it.

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