I just connected my TV to my Laptop. The ATI card has a setting in the Control Panel to output stuff either to the LCD screen or the TV.

ATI conveniently included a hotkey feature for changing settings, but it only works for going to LCD. When I go to TV, there is a confirmation dialog box with "No" as default. And using the hotkey it just goes past this dialog with "No, I don't want to change setting". Doing it manually works of course.

So, I used Perl and Win32::GuiTest to do it manually, only automatically :)

This is very specific to the particular thing I do here, but the general approach could possibly be useful to someone.

  1. Create a shortcut of the Display icon in the Control Panel
  2. Put the code below in enable-s-video.pl
  3. Create a shortcut of the Perl script and put it in the Start Menu. Assign a hotkey (Ctrl-Shift-Alt-T for TV) and select Run-as-minimized.

#!/usr/bin/perl -w #enable-s-video.pl use strict; use Win32::GuiTest qw(FindWindowLike GetWindowText GetForegroundWindow + SetForegroundWindow SendKeys); sub waitForSeconds { select(undef, undef, undef, $_[0]); } system("start ControlPanel-Display"); waitForSeconds(0.3); my ($hwindDisplay) = FindWindowLike(0, "^Display Properties", ""); $hwindDisplay or die("Could not open Control Panel - Display\n"); SetForegroundWindow($hwindDisplay); #Settings Tab SendKeys("^+{TAB}"); #Advanced Button SendKeys("%v"); #Dusplays Tab SendKeys("^{TAB}") for(1..5); #Move to the bottom of the Scheme combobox SendKeys("{DOWN}") for(1..10); #OK Button SendKeys("{ENTER}"); #Leave it time to change mode waitForSeconds(1); #Did we change the settings? Then we need to confirm the dialog box. SendKeys("{TAB}{SPACEBAR}") if(GetWindowText(GetForegroundWindow()) =~ + /^ATI Property Page/); #Close dialog SetForegroundWindow($hwindDisplay); SendKeys("{ENTER}"); __END__

/J

Replies are listed 'Best First'.
Re: Enable S-Video output
by ackme (Scribe) on Jan 04, 2004 at 09:27 UTC
    Thanks! Sometimes you just need a starting point, which this was for me. I started playing with this and now it is helping me.
    #!/usr/bin/perl -w use strict; my @windows; use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendMouse MouseMoveAbsPix); $Win32::GuiTest::debug = 1; # Set to "1" to enable verbose mode my ($hwindDisplay) = FindWindowLike(0, "^Foo", ""); $hwindDisplay or die("Could not open Foo\n"); SetForegroundWindow($hwindDisplay); MouseMoveAbsPix(140, 380); SendMouse ("{LEFTCLICK}");
    I'm using "MouseMoveAbsPix" until I get it to recognize the box name, which it hasn't yet, or until I can figure out the process ID for it, but I can't tell you what a treat it is to get this automated! Looking back at it, it seems so idiotically simple, but at some point you have to actually sit down and make yourself do it. What slowed me down was the fancy brackets ({}) around LEFTCLICK. I didn't see why they were necessary on top of the parens AND quotes (and still don't), but they made it work.

    (This is for a job where I am literally supposed to "click a button," to guarantee that the app "Foo" is running. I'll do the alarm programming one of these days, but since this won't work if the app isn't running, I'm not in any big hurry about it. Actually, the "or die" should be enough! Now that I think about it, I will need to add some kind of "wait 1800, repeat" routine too, but I can do that later. Did I mention "lazy"?)

    But you were right, I ended up using it for something completely different. And the fun thing is, I have about 20 more routines I am going to apply it to over the next couple of weeks.

    Also, if anyone sees a better WTDI, please feel free. I am usually missing something. TIA.

    ackme

      If you had read the Win32::GuiTest documentation, you would have seen that it handles buttons. You need to use a combination of FindWindowLike and PushChildButton.