PDA

Click to See Complete Forum and Search --> : Get Mouse Click Positon


dkaylor
Nov 23rd, 1999, 12:27 AM
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.

Aaron Young
Nov 23rd, 1999, 12:31 AM
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..

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
aarony@redwingsoftware.com
adyoung@win.bright.net

dkaylor
Nov 23rd, 1999, 12:55 AM
I have done it with the timer control, but want to do it without by detecting the mouse click event. Thanks

Aaron Young
Nov 23rd, 1999, 01:01 AM
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
aarony@redwingsoftware.com
adyoung@win.bright.net


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

dkaylor
Nov 23rd, 1999, 01:50 AM
Guess I was looking for a callback method. Been beating a bunch of options and have not been able to get it.