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

I am a new student of Perl. I wrote an application using TK for user interface. At some point of the program, I need to move the focus from TK to the command prompt windows. Currently I have to move and click the mouse to command prompt windows to get the focus, please show me how to automatically get focus in command prompt windows without using the mouse. Thanks in advance.

Replies are listed 'Best First'.
Re: Command prompt windows
by kcott (Archbishop) on Mar 05, 2014 at 00:52 UTC

    G'day perl4jdd,

    Welcome to the monastery.

    "Currently I have to move and click the mouse to command prompt windows to get the focus, please show me how to automatically get focus in command prompt windows without using the mouse."

    Initially, I had a bit of a chuckle envisioning how you were hoping to achieve this: some sort of widget mind control perhaps :-)

    Did you want to use keystrokes instead of the mouse? If so, the obvious answer would to use Alt-Tab (or equivalent on your system) to change from one application window to another.

    You could set up a Tk::Button with '-command => sub { $mw->iconify }' (see Tk::Wm for details of the iconify() method). [You can invoke buttons using just keystrokes; however, a mouse is more usual.]

    If you wanted this to happen in response to some GUI event, have a look at Tk::bind.

    As you can tell, I'm flailing around in the dark somewhat. If you provide a clearer description of what you do want to do, as opposed to what you don't want to do, a better answer may be forthcoming.

    -- Ken

Re: Command prompt windows
by Anonymous Monk on Mar 05, 2014 at 00:27 UTC

    At some point of the program, I need to move the focus from TK to the command prompt windows.

    No you don't :) think about it

    please show me how to automatically get focus in command prompt windows without using the mouse.

    You don't need to do that :) but if you insist, see Win32, Win32::GuiTest/Win32::GuiTest::Examples... findwindow ... setfocus