Loading ...
Sorry, an error occurred while loading the content.
 

Clicking mouse in client area of window

Expand Messages
  • cadddesignsolutions
    I ve been working with the SendMouseMoveAbs function to test my UI by clicking buttons in my program window. I would really like to be able to send mouse
    Message 1 of 2 , Jul 25, 2003
      I've been working with the SendMouseMoveAbs function to test my UI by
      clicking buttons in my program window. I would really like to be
      able to send mouse clicks to positions in terms of the program
      window's client area. Instead of 0,0 being the upper left corner of
      the screen, I would like it to be the upper left corner of the
      program window. Is this possible, and if so, how do I do it?

      Thanks,
    • Dennis K. Paulsen
      You can try the following... It is a drop-in for Win32::GuiTest and was tested under v1.49.2 of that module. If you know how to add this subroutine
      Message 2 of 2 , Jul 29, 2003
        You can try the following... It is a 'drop-in' for Win32::GuiTest
        and was tested under v1.49.2 of that module. If you know how to add
        this subroutine pristinely yourself, great. Otherwise, to
        crudily "hack" the subroutine into place, find and edit GUITest.pm (?
        \perl\site\lib\win32\) and paste the subroutine itself by the other
        existing subs. Then find the FUNC export tag and add MouseClick
        into the anonymous array (list)... Then you'll finally be able to
        use it in your scripts..... Otherwise there may be something
        similar to this in a future build of Win32::GuiTest.


        #use Win32::GuiTest qw/MouseClick/;.
        ## Example Usage:
        # Click on CE button if its parent window is in foreground
        MouseClick('CE');
        # Right click on CE button if its parent window is in foreground
        MouseClick('CE', undef, undef, undef, '{RIGHT}');
        # Click on 8 button window under the specified parent window; where
        [PARENTHWND] will be replaced by a parent handle variable.
        MouseClick('8', [PARENTHWND]);
        # Click on Calculator parent window itself
        MouseClick('Calculator', GetDesktopWindow());

        sub MouseClick {
        my $window = shift or return(0);
        my $parent = shift || GetForegroundWindow();
        my $x_off = shift || 0;
        my $y_off = shift || 0;
        my $button = shift || '{LEFT}';
        my $delay = shift || 0;

        # Ensure button variable looks ok
        ($button =~ /^\{\D+\}$/) or return(0);
        # Strike } from $button for purpose below
        $button =~ s/\}$//;

        foreach my $child (GetChildWindows($parent)) {
        # Is correct text or window ID?
        if (MatchTitleOrId($child, $window)) {
        my ($x, $y) = GetWindowRect($child);
        # Move mouse to window, +1 for curved windows
        MouseMoveAbsPix(($x + 1) + $x_off, ($y + 1) + $y_off);
        # Press button
        SendMouse($button.'DOWN}');
        select(undef, undef, undef, $delay) if $delay;
        # Release button
        SendMouse($button.'UP}');
        # Success
        return(1);
        }
        }
        # Failure
        return(0);
        }


        Regards,
        Dennis K. Paulsen

        --- In perlguitest@yahoogroups.com, "cadddesignsolutions"
        <sbradley@s...> wrote:
        > I've been working with the SendMouseMoveAbs function to test my UI
        by
        > clicking buttons in my program window. I would really like to be
        > able to send mouse clicks to positions in terms of the program
        > window's client area. Instead of 0,0 being the upper left corner
        of
        > the screen, I would like it to be the upper left corner of the
        > program window. Is this possible, and if so, how do I do it?
        >
        > Thanks,
      Your message has been successfully submitted and would be delivered to recipients shortly.