zby has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to write scripts automating some boring tasks. For this I need to do things like: controlling the mouse and keyboard (pointing to areas on the screen, sending mouse clicks, sending keyboard events etc), raising windows etc. There is a free AutoIt application for that - but it uses it's own language and for me it would be much more convenient if I could use Perl for that. I read Using perl to control spreadsheets but it is about controlling Excel via OLE and in mine case the application does not have any OLE API, or I don't know about it.
  • Comment on perl library for controlling Windows GUI (like AutoIt)

Replies are listed 'Best First'.
Re: perl library for controlling Windows GUI (like AutoIt)
by psychotic (Beadle) on Dec 01, 2005 at 16:51 UTC
    Most of the time you need not manipulate the application by automating mouse clicks. Script the usage of keyboard shortcuts for any functionality you like, use TAB to navigate to buttons, and ENTER respectivelly to activate them. This can be done by exploiting the Windows Scripting Host.
    use strict; use Win32::OLE; my $wsh = new Win32::OLE 'WScript.Shell'; my $targetExactWindowName = "The exact window title of your applicatio +n"; # This brings it to the foreground $wsh->AppActivate( $target ); # Type some keys in the Window, here Ctr+P followed by Enter $wsh->SendKeys('^(p)'); $wsh->SendKeys('{ENTER}');
    You can read more about sendkeys'() peculiarities here: Microsoft link. Of course, you should check if the relevent applicantion exposes some functionality via an OLE server. In that is the case, see if you can get hold of its "Scripting Guide".
Re: perl library for controlling Windows GUI (like AutoIt)
by marto (Cardinal) on Dec 01, 2005 at 16:40 UTC
    Hi zby,

    Have you looked at the Win32::GuiTest module?
    It supports sending of keys, mouse movement and clicks and lots of other helpful things.
    It may be able to help you drive the apps you need to.

    Hope this helps.

    Martin