tags:

views:

126

answers:

1

I have this code:

Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

Dim WindowHandle As Long = FindWindow(vbNullString, "Ultima Online")

SendMessage(WindowHandle, MOUSEEVENTF_LEFTDOWN, 0, 0)
SendMessage(WindowHandle, MOUSEEVENTF_LEFTUP, 0, 0)

I know it is getting the windowhandle fine, because I made a conditional statment that pops up a messagebox if windowhandle = 0

The problem is that it is not sending the mouse click to the window.

A: 

You should be using different constants for SendMessage:

Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202 

Dim WindowHandle As Long = FindWindow(vbNullString, "Ultima Online")

SendMessage(WindowHandle, WM_LBUTTONDOWN, 0, 0)
SendMessage(WindowHandle, WM_LBUTTONUP, 0, 0)

Notice that you are also sending coordinates at 0,0 - but I will assume that this is fine.

P.S.These constants that you are currently using are for mouse_event function which is little bit more low-level:

Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Josip Medved
Its still not working, do I have to make the "Ultima Online" window active or something?