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

1529Halting a gui-test script with a key stroke

Expand Messages
  • evenprime
    Oct 8, 2006
      How can I detect a key stroke (ala ESC) to stop a GUI-test script

      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


      use Win32::GuiTest qw/:ALL/;

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

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

      while (<DATA>) {
      if ( IsKeyPressed(ESC) ) {
      else {
      SetForegroundWindow( $main_win[0] );
      sleep 1;
      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! ;-{)}
      the end!