How to find my information

  • Thread starter Thread starter Morten Snedker
  • Start date Start date
M

Morten Snedker

At the moment I wish to figure out how to perform a mouse click at a
given position on the screen.

Someone probably has the solution, but I rather want to learn to find
out myself.

So, could someone push me in the right direction, as how to retrieve
the information from MSDN?

I know I should be using the an API of user32.dll, but besides that I
find it difficult to know what to find where. Any thumb-rules I can
take into consideration?

Where is the right place / search routine, when I wish to find out of
API's e.g. in connection with mouse and keyboard activity?

Regards /Snedker
 
hi, check out www.allapi.net, they have a great library of API functions,
plus VB examples of almost all of them. theyve been very helpful to me in
giving good information for API calls.
 
Rather than using MSDN, I have better success using Google to search
the web and groups for this kind of thing.

Picking the right search terms, that will give you what you want
without being too broad or limiting, is the trick. You know you want
to perform a specific task. You know it will involve an API call;
which, since you're doing it in VB, will require a Declare. So, for
your query, try something like:

simulate mouse click declare

And I guarantee you'll find it quickly. :)

Oh, one more hint. There's more than one way to do it. Even a way
that doesn't require moving the mouse pointer at all, if that's
something you're interested in.
 
Oh, one more hint. There's more than one way to do it. Even a way
that doesn't require moving the mouse pointer at all, if that's
something you're interested in.

Hit me! :-)

/Snedker
 
Morten said:

It's been a long time since I've done this, but it involves sending the
Windows messages directly to the control that it would normally
receive.

First, you need the handle (hWnd) of the control:

1) Get the visible control for a given screen location using API
WindowFromPoint (easy), or
2) Call API GetWindow recursively to search for a control by
WindowName/ClassName/Text (harder, but you can "click" things not even
visible)

Then, use API PostMessage to send the appropriate messages to that
hWnd. You can see the messages that a control receives during normal
mouse/keyboard interaction by using a tool like WinSpy to intercept and
display them.

Here's where my memory gets a bit fuzzy. If I recall, a few controls
will respond just fine to a single WM_CLICK message, but most prefer a
WM_LBUTTONDOWN followed by a WM_LBUTTONUP. I found some code in an old
VB6 program of mine, and removed the non-relevant stuff; this should at
least give you the idea:

-----

Private Type LongInt
lng As Long
End Type
Private Type LoHiWord
lw As Integer
hw As Integer
End Type

Sub LeftClickAt(ByVal hWnd as Long, ByVal X as Long, ByVal Y as Long)
' virtual click left mouse button (I think X/Y were control
coordinates, not screen)
SendMouseEvent hWnd, WM_MOUSEMOVE, X, Y
SendMouseEvent hWnd, WM_LBUTTONDOWN, X, Y
SendMouseEvent hWnd, WM_LBUTTONUP, X, Y
SendMouseEvent hWnd, WM_MOUSEMOVE, X, Y
End Sub

Private Function SendMouseEvent(ByVal hWnd As Long, ByVal lMsg As Long,
ByVal nX As Long, ByVal nY As Long) As Long
' Sends a virtual mouse message directly to a window.
Dim l1 As Long
Dim li As LongInt
Dim lhw As LoHiWord
lhw.lw = nX
lhw.hw = nY
LSet li = lhw
SendMouseEvent = PostMessage(hWnd, lMsg, ByVal l1, ByVal li.lng)
End Function
 
On 10 Oct 2006 14:40:52 -0700, (e-mail address removed) wrote:

Your help is mostly appreciated. I'll give it at go along the day and
let you know how it went. Thanks again.

Regards /Snedker
 
Back
Top