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

141SendKeys to a dialog box

Expand Messages
  • rap101992 <palladinob@toysrus.com>
    Dec 11, 2002
    • 0 Attachment
      I'm a first time user to this group so please bear with me...

      I'm trying to click (mouse click, Enter, spacebar, anything) on a
      dialog box's "OK" button. The dialog box is an Application Error
      dialog box on a remote Windows NT system. The dialog box is from an
      application (spdirector.exe) that executed an illegal memory write.
      It seems that this is a system dialog box (?) and I can't find it's
      handle. I can't issue anything to it, it just seems to be ignored.
      I've included the main part of my program (with some editing for
      briefness).

      The SECOND PART in my program just tried to click/<CR> on any handle
      I found. That didn't work either.

      For "normal" applications, the module works great! I programmed two
      entire games of FreeCell using mouse moves and clicks just to get
      familiar with the module.

      We do a lot of remote PC management and this is a great tool if I can
      just get rid of the error dialog box!

      Also, I was reading the Win::GuiTest.pm source code and can't figure
      out where "SendKeysImp" is located. Its the last statement in the
      SendKeys subroutine but where is it located; what does it do; is
      there any documentation on it; etc.?

      Thanks for any help for anybody,

      Bob



      #!/usr/bin/perl -w

      use POSIX;
      use strict;

      use Win32::GuiTest qw/
      FindWindowLike
      GetChildDepth
      GetChildWindows
      GetClassName
      GetDesktopWindow
      GetScreenRes
      GetWindowRect
      GetWindowText
      IsCheckedButton
      IsWindow
      SendKeys
      SetForegroundWindow
      WMGetText
      MouseMoveAbsPix
      SendLButtonDown
      SendLButtonUp
      GetCursorPos
      PushChildButton
      PushButton
      /;

      #
      # Window text pattern we're looking for. Remember, its a pattern!
      #

      my $window = "spdirector.exe";

      my $path = ""; # Local path
      my $dfile = ""; # Debugging filespec
      my $handle = 0; # Window-of-interest's
      handle
      my $debug = ""; # Debug print flag
      my $drive = ""; # Current working disc
      drive
      my $text = ""; # Returned window text
      my $host = ""; # Who am I?
      my $ok = ""; # A response
      my $x = ""; # X, Y co-ordinates
      my $y = "";
      my $i = ""; # Just a counter
      my $d6 = "";
      my $d7 = "";
      my $d8 = "";

      my @wins = (); # Array of window handles

      #
      ######################################################################
      #
      #
      # Start of Execution
      #
      ######################################################################
      #
      #

      $host = $ENV {COMPUTERNAME}; # My host name

      $path="c:/progra~1/perl/scripts/spdirector/";

      $dfile = $path . "spdir_debug.txt"; # Debugging filespec

      #
      # Check if the debug file, SPDIR_DEBUG.TXT, exists. If it doesn't,
      # just skip this part. If it does, check the size of the file to
      ensure
      # we don't fill up the disc drive. If the file is over 10Mb, clobber
      # it and start a new recording.
      #

      $debug = 0;
      if (-e $dfile)
      {
      $i = -s $dfile; # Get the file's size
      if ($i < 10000000)
      {
      open (DB, ">> $dfile"); # Append to it
      print DB ("\n\n");
      }
      else
      {
      open (DB, "> $dfile"); # Clobber and write to it
      print DB ("Debug file for SPDIRECTOR.PL\n\n");
      }
      $debug = 1;
      }

      if ($debug != 0) { print DB ("Host: $host \n\n"); }

      $Win32::GuiTest::debug = 0; # 0 => normal mode
      # 1 => enable verbose mode

      @wins = FindWindowLike(0, "", ""); # Finds ALL windows

      for ($i=0; $i<@wins; $i++) # Look through all the
      handles
      {
      $text = GetWindowText($wins[$i]); # Get the window text

      if ($debug != 0) { print DB ("$wins[$i]\t,$text\n"); }

      if ($text =~ /$window/) # Is it "our" window?
      {
      $handle = $wins[$i]; # Got it!

      SetForegroundWindow($handle); # Make it foreground
      PushChildButton($handle,"OK",.25);
      $ok = FindWindowLike($handle, "", "OK");
      ($x, $y) = GetWindowRect($handle);
      MouseMoveAbsPix($x+2,$y+2);
      sleep (1);
      SendKeys("~{SPACEBAR}~");
      SendLButtonDown();
      SendLButtonUp();

      if ($debug != 0)
      {
      print DB
      ("\n**************************************************\n\n");
      print DB ("Found - \n");
      print DB (" Window text : $text\n");
      print DB (" Window handle: $handle\n");
      print DB (" OK value : $ok\n");
      print DB (" OK (x,y) : $x, $y\n");
      print DB (" Issued : Left mouse button - Down/Up -
      <CR><SP><CR>\n");
      print DB
      ("\n**************************************************\n\n");
      }
      }
      }

      # SECOND PART

      print DB ("\nDesktop - \n");
      my $desk = GetDesktopWindow();
      print DB ("$desk\n");

      print DB ("\nSome - \n");
      my @some = FindWindowLike($desk,"","");
      foreach $x (@some)
      {
      $y = GetWindowText($x);
      my $z = GetClassName($x);
      print DB ("$x\t,$y\t,$z\n");
      if ($z =~ /32770/)
      {
      print DB ("\t,----------> Found class #32770 \n");
      print DB ("\nChild - \n");
      PushButton("OK",0.25);
      SendKeys("~{SPACEBAR}~");
      my @childs = GetChildWindows($x);
      foreach $d8 (@childs)
      {
      $d7 = GetWindowText($d8);
      print DB (" $d8\t,$d7\n");
      PushChildButton($x,$d8,0.25);
      SendKeys("~{SPACEBAR}~");
      }
      print DB ("\n");
      SetForegroundWindow($x);
      SendKeys ("~{SPACEBAR}~");
      }
      }
      print DB ("\n");




      if ($debug != 0) { close (DB); }

      exit;
    • Show all 2 messages in this topic