Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

mouse_event fails

The following code sets the cursor where I want it.
I can manually left click and gain focus on the text box that is pointed to.
However, there is no response when I execute the "mouse_event".

Searching the net I find many web site references to similar problems that site "SetWindowsHookEx API" which I simply cannot comprehend. I need help.

Const MOUSEEVENTF_LEFTDOWN = &H2
' left button down
Const MOUSEEVENTF_LEFTUP = &H4
' left button up

'Private Declare Sub mouse_event Lib "user32" _
'(ByVal dwFlags As Long, ByVal dX As Long, _
'ByVal dY As Long, ByVal dwData As Long, _
'ByVal dwExtraInfo As Long)


xPos = (WebBrowser.Top + 1.4 * WebBrowser.Height) / Screen.TwipsPerPixelX
yPos = (WebBrowser.Left + 0.25 * WebBrowser.Width) / Screen.TwipsPerPixelY
' Move cursor to destination, first
SetCursorPos xPos, yPos: Sleep 500

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 250
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 250

Winnie-the-Pough
[1179 byte] By [dmb-job] at [2007-11-11 8:10:22]