🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.vb.winapi
Article #9

mouse_event help needed

#9
From: bowchow79
Date: Sun, 05 Feb 2006 22:43
34 lines
3216 bytes
I have an application for which I'd like to simulate mouse clicks.
What I want to do is simulate a click at a specific location in the
application.  I've tried PostMessage to no avail.  I had a bit more
success with mouse_event, however even this doesn't seem to actually
send a click in this application.  The code is roughly as
follows (targetHwnd is the hWnd of the target window I'd like to click
in, and targetX/targetY are the x/y coordinates on the screen I want to
click at):

<code>
ForceForegroundWindow(targetHwnd);
int x = targetX * 65536 / Screen.PrimaryScreen.Bounds.Width;
int y = targetY* 65536 / Screen.PrimaryScreen.Bounds.Height;
mouse_event(MOUSEEVENTF_MOUSEMOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
</code>

This code works fine simulating a mouse click in every other
application I've tried.  However, the one I'm interested in does not
respond - the window is brought to the foreground and gains input
focus, the mouse moves to the desire location at which point the
application changes the cursor's icon, and nothing happens.  This code
works in creating a mouse click for any other application I've tried.

One thing to note about this application in which I'm trying to
simulate the click is that it does not have any child windows.  There
are no buttons or forms whose hWnds I can grab.  It appears to render
all buttons, scrollbars and such itself, without using Windows.  I have
no clue why it doesn't seem to receive clicks - is there anything
anyone can think of that would explain this behavior?  Hopefully I'm
just missing something about emulating mouse clicks in Windows.
Technical Details
Message-ID: <1139179439.013311.39470@f14g2000cwb.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 104093,7c284b3b127661a5,start
X-Google-Thread: 1091e5,7c284b3b127661a5,start
X-Google-Thread: 11493c,7c284b3b127661a5,start
X-Google-Thread: 110c1b,7c284b3b127661a5,start
X-Google-Thread: 10b845,7c284b3b127661a5,start
X-Google-Attributes: gid104093,gid1091e5,gid11493c,gid110c1b,gid10b845,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail
From: "bowchow79" <bowchow79@hotmail.com>
Newsgroups: microsoft.public.vb.winapi,borland.public.delphi.winapi,microsoft.public.vb.general.discussion,microsoft.public.win32.programmer.ui,microsoft.public.dotnet.languages.csharp
Subject: mouse_event help needed
Date: 5 Feb 2006 14:43:59 -0800
Organization: http://groups.google.com
Lines: 35
Message-ID: <1139179439.013311.39470@f14g2000cwb.googlegroups.com>
NNTP-Posting-Host: 128.36.58.187
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1139179444 10575 127.0.0.1 (5 Feb 2006 22:44:04 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 5 Feb 2006 22:44:04 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: f14g2000cwb.googlegroups.com; posting-host=128.36.58.187;
   posting-account=Uqyi_gwAAABGxVlZmh0G9E772RXVicLx