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

Here is my code:

use Win32::CtrlGUI my $window = Win32::CtrlGUI::wait_for_window(qr/Notepad/); $window->send_keys("!fx");

This is actually the same exact code that appears in the POD. When I run the program, it blocks, then I open notepad, and the call returns, but $window is null. This is confusing because it obviously found the notepad window opening. Does anyone have any insights?

Thanks!

Replies are listed 'Best First'.
Re: Win32::CtrlGui::wait_for_window is only partially working
by southampton (Novice) on Feb 28, 2005 at 19:19 UTC
    Putting a semicolon after the

    use Win32::CtrlGUI

    line seems to fix it.

    Without the semicolon, I got an error on the send_keys line. With it, everything worked.

Re: Win32::CtrlGui::wait_for_window is only partially working
by fglock (Vicar) on Feb 28, 2005 at 20:53 UTC

    Try inserting a pause:

    use Win32::CtrlGUI; my $window = Win32::CtrlGUI::wait_for_window(qr/Notepad/); sleep 1; $window->send_keys("!fx");

    I had a similar problem, with an application that was taking too long to finish drawing it's window.

    If you had the same problem, you would have to check if specific fields inside the window are already drawn before sending keys.