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

Halting a gui-test script with a key stroke

Expand Messages
  • evenprime
    How can I detect a key stroke (ala ESC) to stop a GUI-test script immediately? I m experimenting with gui-test to automate an old windows app with no macro
    Message 1 of 1 , Oct 8, 2006
    • 0 Attachment
      How can I detect a key stroke (ala ESC) to stop a GUI-test script
      immediately?

      I'm experimenting with gui-test to automate an old windows app with no
      macro features or OLE support of any kind. Works great, but the
      problem is that I'm using a while loop to iterate over a lines of
      __DATA__ and, heh, things can go wrong now and then and I need to kill
      the script.

      It's hard to do when I can't get to the commandline because the script
      is constantly making sure the app is in the foreground (quite
      necessary). So I'm trying to use the IsKeyPressed, but, meh, it
      doesn't act very quickly and I need to hold down the ESC key till the
      next loop.

      e.g., a dumbed down version featuring notepad

      #!perl

      use Win32::GuiTest qw/:ALL/;

      my @main_win = FindWindowLike( undef, "Untitled - Notepad" );

      system("start notepad.exe");
      sleep 2;

      while (<DATA>) {
      if ( IsKeyPressed(ESC) ) {
      exit;
      }
      else {
      chomp;
      SetForegroundWindow( $main_win[0] );
      sleep 1;
      SendKeys("$_");
      SendKeys("{ENTER}");
      }
      }
      __DATA__
      type this
      type that
      hold the ESC key down now
      The perl script should halt
      by now for sure
      Hey, you're not paying attention! ;-{)}
      !
      :-P
      the end!
    Your message has been successfully submitted and would be delivered to recipients shortly.