Monday, May 11, 2009

Loading Perl's Win32::GuiTest

The Win32::GuiTest allows perl scripts run under Windows to send keyboard and mouse events to Win32 programs. George Nistorica wrote an article on how to do this; I've summarized what you need to do here.

  1. Run ppm (the perl package manager)
  2. Type 'install Win32::GuiTest'
  3. Add the following code to your perl script:
    use Win32::GuiTest qw(IsWindow FindWindowLike SendKeys
    PushButton SetActiveWindow SetForegroundWindow GetWindowRect MouseMoveAbsPix SendMouse);
    (Note that each function you need to call should be listed in this enum-- I've listed the most common ones
  4. Bring your window to the foreground:
    sub bring_window_to_front {
    my $window = shift;
    my $success = 1;

    if ( SetActiveWindow($window) ) {
    print "* Successfully set the window id: $window active\n";
    }
    else {
    print "* Could not set the window id: $window active\n";
    $success = 0;
    }
    if ( SetForegroundWindow($window) ) {
    print "* Window id: $window brought to foreground\n";
    }
    else {
    print "* Window id: $window could not be brought to foreground\n";
    $success = 0;
    }

    return $success;
    }

No comments:

Labels

Blog Archive

Contributors