PDA

Click to See Complete Forum and Search --> : mouse_event


TheLeeMan
Apr 29th, 2000, 12:01 PM
Hello-

I'm trying to get the mouse_event API to work but am having problems. I am trying to move the mouse usin GetCursorPos and then synthesize a mouse click but when I call the mouse_event API sub-procedure nothing happens - no error - no nothing. Does anyone have a working example of this code or can give me an idea of what I am doing wrong? Relevent bits of my code is as follows:

Declarations:
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)

Mousedown:
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0

Mouseup:
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Module:
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4


Any ideas? Thanks or your help!

[Edited by TheLeeMan on 04-30-2000 at 01:02 AM]

Apr 30th, 2000, 04:02 AM
Your mouse leftclick up and down and yer declaration look fine, but i dont know how u were gettin yer mouse to move with GetCursorPos.. To simulate a mouse move, u gotta use the mouse_event API.
Fer Examp:

MOUSEEVENTF_MOVE = &H1
mouse_event MOUSEEVENTF_MOVE, 25, 75, 0, 0

the 25 is the x coordinate and 75 is the y.
Now that command will move u 25,75 relative from the current mouse position, to move to absolute screen coordinates do this:

MOUSEEVENTF_ABSOLUTE = &H8000
MOUSEEVENTF_MOVE = &H1
mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE, 25, _ 75, 0, 0

That command will move u to the absolute screen coordinates of 25,75.
I hope this helps.. another thing maybe that yer sending the click to early, maybe sleep for a second or two before sending the click.. (mouse_event can get tricky to work with cuz its doesnt return anything)

CiD -=ii=-

TheLeeMan
Apr 30th, 2000, 05:37 PM
I was using the API to move the mouse and it was moving just dandy. I could move the mouse all day, I just cann't get it to click.

Do you know anything about synthesizing the mouse clicks using the moues_events?

Thanks

May 1st, 2000, 06:06 AM
yer mouse click looks fine.. the only other idea i have would be to make the program sleep fer like 2 seconds right before u send the click. sometimes when im passing keys to a form, i send the keys too early (before the new form is accepting data). this would assure that the clicks r not getting sent too early...
maybe that applies to yer situation...

CiD -=ii=-