I am trying to communicate with a perl/Tk status bar from another application in Windows NT. I thought I should be able to bind an action to a mouse click and then send simulated mouse clicks to it from my application. Then the status bar would be up-to-date with the current state of the application without interfering with it. If possible, I want to simulate mouse clicks to the target window without actually grabbing and moving the mouse.

I have tried two ways of doing it and both are not working: Win32::GuiTest and Win32::CtrlGUI.

Here is the first way, using Win32::GuiTest.
use strict; use Win32::GuiTest qw(FindWindowLike GetChildWindows GetWindowText GetWindowID SetActiveWindow SetForegroundWindow PostMessage); sub WM_LBUTTONDOWN { 0x0201; } sub WM_LBUTTONUP { 0x0202; } my @winlst; my $tries = 0; while ($tries < 20) { print "trying to find the window\n"; @winlst = FindWindowLike(0,'StatusBar','TkTopLevel'); last if scalar(@winlst) > 0; $tries++; sleep 1; } if (@winlst == 1) { my $status = $winlst[0]; my $i; my $x = 30; my $y = 14; my $xy = ($y << 16) + $x; print "trying to send a click to the window\n"; SetForegroundWindow($status); SetActiveWindow($status); PostMessage($status, WM_LBUTTONDOWN, 0x0001, $xy); PostMessage($status, WM_LBUTTONUP, 0, $xy); }
Here is the second way, using Win32::CtrlGUI.
use strict; use Win32::CtrlGUI; my $win = Win32::CtrlGUI::wait_for_window("ParpadStatus"); my $x = 30; my $y = 14; my $xy = ($y << 16) + $x; print "trying to send a click to the window ", sprintf("0x%lx",$win->handle),"\n"; $win->post_message('NN', "WM_LBUTTONDOWN", 0x0001, $xy); $win->post_message('NN', "WM_LBUTTONUP", 0, $xy);
In both cases Spy++ shows that the window is getting the button events, but it isn't responding. There are also some unusual messages in the log in both cases about a message 0x118:
003000BE R WM_ACTIVATE 003000BE P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:30 yPos:14 003000BE P WM_LBUTTONUP fwKeys:MK_LBUTTON xPos:30 yPos:14 003000BE P message:0x118 [Unknown] wParam:0000FFF8 lParam:A00885B9 003000BE S WM_NCACTIVATE fActive:False 003000BE R WM_NCACTIVATE fDeactivateOK:True
Does anyone have ideas about how I can get this to work, or if I should abandon it for better ways? I would rather not use sockets, because later I want to communicate asynchronously with other more complicated perl/Tk applications.

In reply to Simulating mouse clicks in Windows by tall_man

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.