Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simulate Mouse Click using SendInput Win API call

1,753 views
Skip to first unread message

ronniepo

unread,
May 22, 2009, 4:33:48 PM5/22/09
to
Has anyone had any luck simulating a left mouse click using
the SendInput Win32 API function?

I've seen numerous examples on how to use the older
Mouse_Event() function, but this doesn't seem to work
(crashes) in Windows XP.

Jerry Siegel [TeamSybase]

unread,
May 23, 2009, 11:05:21 AM5/23/09
to
Start with http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx
What does your code look like?

--
Report Bugs: http://case-express.sybase.com/cx/welcome.do
Product Enhancement Requests:
http://my.isug.com/cgi-bin/1/c/submit_enhancement

<Ronnie Po> wrote in message news:4a170c2c.2a3...@sybase.com...

ronniepo

unread,
May 25, 2009, 2:27:38 AM5/25/09
to
That msdn topic is what inspired me to issue a call for help
here. As a non-VB programmer, I wasn't quite sure how to
translate the parameter types when declaring the global
external function for SendInput().

For what it's worth, my implementation of Mouse_Event(),
which crashes with a "Bad runtime function" message in
Windows XP, looks like this:

/* Declare Global External Functions. */
FUNCTION boolean SetCursorPos(int cx, int cy) LIBRARY
"User32.dll"

SUBROUTINE Mouse_Event(ulong dwflag,ulong dx,ulong dy,ulong
cbutton,ulong dwextra) LIBRARY "User32.dll"

//dwflag: 1 = do nothing, 7 = L-button clicked, 25 =
R-button clicked


/* Position cursor and simulate mouse click */
integer li_x, li_y

/* After successfully setting li_x and li_y to the desired
pixel coordinates: */

SetCursorPos(li_x, li_y) // This part works

Mouse_Event(7, 0, 0, 0, 0) // "Bad runtime function
reference..."

Chris Pollach

unread,
May 25, 2009, 7:07:48 AM5/25/09
to
Hi Ronnie;

Why not just use the built-in PB SEND method?

For example ... LHMB on an SLE within a window:

Send(Handle(wm_mywin), 273, 0, Handle(sle_1))

hth

--
Regards ... Chris
ISUG - NA RUG Director
http://chrispollach.pbdjmagazine.com


<Ronnie Po> wrote in message news:4a170c2c.2a3...@sybase.com...

Jerry Siegel [TeamSybase]

unread,
May 25, 2009, 11:54:38 AM5/25/09
to
I'm looking at http://msdn.microsoft.com/en-us/library/ms646260.aspx and it
shows the function name as mouse_event with lower case. That may be why it
is not found, see the first gotcha on http://www.sybase.com/detail?id=44648

<Ronnie Po> wrote in message news:4a1a3a5a.1bb...@sybase.com...

ronniepo

unread,
May 26, 2009, 12:46:44 PM5/26/09
to
Wow. That solved it. It didn't even occur to me to consider
the case.

Thanks for pointing that out, Jerry.


> I'm looking at
> http://msdn.microsoft.com/en-us/library/ms646260.aspx and
> it shows the function name as mouse_event with lower
> case. That may be why it is not found, see the first
> gotcha on http://www.sybase.com/detail?id=44648
>
> --
> Report Bugs: http://case-express.sybase.com/cx/welcome.do
> Product Enhancement Requests:
> http://my.isug.com/cgi-bin/1/c/submit_enhancement
>
> <Ronnie Po> wrote in message
> > news:4a1a3a5a.1bb...@sybase.com... That msdn
> > topic is what inspired me to issue a call for help here.
> > As a non-VB programmer, I wasn't quite sure how to
> > translate the parameter types when declaring the global
> external function for SendInput(). >
> > For what it's worth, my implementation of Mouse_Event(),
> > which crashes with a "Bad runtime function" message in
> > Windows XP, looks like this:
> >
> > /* Declare Global External Functions. */
> > FUNCTION boolean SetCursorPos(int cx, int cy) LIBRARY
> > "User32.dll"
> >
> > SUBROUTINE Mouse_Event(ulong dwflag,ulong dx,ulong dy

> > ,ulong cbutton,ulong dwextra) LIBRARY "User32.dll"

0 new messages