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

I have a Perl Tk and a graphical none Perl application working together. The none Perl application is started from the Perl application with the code:
$ppc = Win32::Process::Create( $global_process, $command_a, $command_b, 0, NORMAL_PRIORITY_CLASS, '.' );
The none Perl application creates a file that the Perl application is ‘waiting’ for. When the file is found, the Perl application brings up a Tk window that is completed by the user. The none Perl application is then used agaian. The problem is that the keboard in the none Perl application only become 'active' after the left mouse key has been pressed. It is though the 'focus' (or something like this) is not being released after the Tk window has been completed. I have added the following lines just before the none Perl application is used again.
$mw_Main->grabRelease; $mw_Main->withdraw; $global_process->Resume();
This did make things any better (or worse). Has anyone any ideas ho I can prevent the need to use the left mouse button before the keys become active?

20050516 Edit by castaway: Changed title from 'Ineraction of Perl and applications not written in Perl'

Replies are listed 'Best First'.
Re: Interaction of Perl and applications not written in Perl
by bart (Canon) on May 12, 2005 at 23:45 UTC
    Take a look at Win32::GuiTest. That module allows some spiffy interaction with the GUI part of other applications' windows. In particular, the SetForegroundWindow looks like it could work, together with GetForegroundWindow to get the hWnd for that app's main window, or, if that doesn't work out, with FindWindowLike.
Re: Interaction of Perl and applications not written in Perl
by starbolin (Hermit) on May 12, 2005 at 16:50 UTC

    You have to obtain the handle of the window you want focus in then call set focus on that handle. From Gtk+ in X I can do this:

    XRaiseWindow(GDK_DISPLAY(), (Window) x_win); XSetInputFocus(GDK_DISPLAY(), (Window) x_win), RevertToParent, CurrentTime);
    The calls for windows may be different.

    Gentle reminder: When posting snippets of code to PM they look nicer if you put < code></code> around the snippit. Like this:

    $ppc = Win32::Process::Create( $global_process, $command_a, $command_b, 0, NORMAL_PRIORITY_CLASS, '.' );

    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}