Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Manually Select a Windows Window

by rd48sec (Novice)
on Feb 21, 2017 at 16:56 UTC ( [id://1182448]=perlquestion: print w/replies, xml ) Need Help??

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

I have an experimental Perl script that selects a Notepad window and writes some text to it. My code works.

If I have more than one Notepad window open, I would like to be able to manually select which window to write to. Is there a way to do this?

#!/PERL5 use strict; use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendKeys); $ARGV[0] =~ s/\[!20\]//g; #Remove [!20] WinkeySim delays $ARGV[0] =~ m!\((.*)\)!; #Grab everything between ( ) put i +nto $1 my $EEcorr = "{(}".$1."{)}"; #Parentheses (special characte +rs) are added #Write to unit EEPROM #my @window = FindWindowLike(0, "Terminal", ""); my @window = FindWindowLike(0, "Notepad", ""); SetForegroundWindow($window[0]); sleep 1; Win32::GuiTest::SendKeys($EEcorr,20);

Replies are listed 'Best First'.
Re: Manually Select a Windows Window
by LanX (Saint) on Feb 21, 2017 at 17:18 UTC
    I suppose one of those should do
    HWND GetFocus(hwnd) *AHWND GetActiveWindow(hwnd) *AHWND GetForegroundWindow() *

    Did you try?

    Of course you should check if the result belongs to the set of NotePad windows.

    Untested!

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re: Manually Select a Windows Window
by stevieb (Canon) on Feb 21, 2017 at 17:19 UTC

    As you've already found, FindWindowLike() returns a list of all open windows of that type, and after a quick test, they are returned in the order of most recently opened to first opened:

    Code:

    my @window = FindWindowLike(0, "Notepad", ""); print "$_\n" for @window;

    Open one window:

    8455346

    2nd window opened:

    7931554 8455346

    3rd:

    11731214 7931554 8455346

    Differentiating between the windows other than the order they were opened is something I don't have time to review the docs for right now, so you may want to look to see if there are other identifiers or not.

      No way to have Perl wait for a mouse click on any window and then send the data?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1182448]
Approved by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found