Jump to content

switching monitors


Recommended Posts

Hello everyone, I am a complete newb to autoit and would like a little help.

I would like to make a script that will disconnect one of my monitors and extend the desktop to my TV. At the moment I do it manually by going to control Panel>Appearance and Personalization>Display>Screen Resolution Then I select display 1 (my tv) and extend to desktop and  then select display 2 ( one of my monitors) disconnect display. I also have a 3rd monitor connected as my main monitor. I dont want you guys to write a script for me but just help me getting started "point me in the correct direction".

Thank you Aareleb. 

Link to comment
Share on other sites

  • 1 year later...

Here is the script I created for this topic Thank you. It is not that great but my first script. Let me know what you guys think.

Aareleb

#include <GUIConstantsEx.au3>

Global $Timer1 = 500;
Global $Timer2 = 150;
Global $ScreenResScreen1 = "rundll32.exe shell32.dll,Control_RunDLL desk.cpl";
Global $ScreenRes1 = "Screen Resolution";
Global $DisplaySettings1 = "Display Settings";
Global $ComboBoxInstance1 = "[CLASS:ComboBox; INSTANCE:1]";
Global $ComboBoxInstance2 = "[CLASS:ComboBox; INSTANCE:2]";
Global $ComboBoxInstance3 = "[CLASS:ComboBox; INSTANCE:3]";
Global $ButtonInstance1 = "[CLASS:Button; INSTANCE:1]";
Global $ButtonInstance4 = "[CLASS:Button; INSTANCE:4]";
Global $Up1 = "{UP}";
Global $Down1 = "{DOWN}";

Local $aGUI = GUICreate("Switcher v1.0", 258, 114, 401, 181)
$TV1 = GUICtrlCreateButton("TV", 5, 14, 100, 35)
$Monitor1 = GUICtrlCreateButton("Monitor", 152, 14, 100, 35)
GUISetState(@SW_SHOW, $aGUI)

While 1
    Switch GUIGetMsg()
        case $GUI_EVENT_CLOSE
Exit

;disable Monitor (HP w1907) and enable HDTV
Case $TV1
Run($ScreenResScreen1)
Sleep($Timer1)
WinSetTrans($ScreenRes1, "", 0)
Sleep($Timer2 )
ControlSend($ScreenRes1, "",$ComboBoxInstance1, $Up1) ; Selects display #1
Sleep($Timer2 )
ControlSend($ScreenRes1, "",$ComboBoxInstance3, $Up1) ;Sets display #1 "extend desk top to this display"
Sleep($Timer2 )
ControlSend($ScreenRes1, "",$ComboBoxInstance1, $Down1) ; Selects display #3
Sleep($Timer2 )
ControlSend($ScreenRes1, "",$ComboBoxInstance1, $Down1) ; Selects display #3
Sleep($Timer2 )
ControlClick($ScreenRes1, "",$ComboBoxInstance3 ) ;Sets display#3 "Disconnect this display"
Sleep($Timer2 )
ControlSend($ScreenRes1, "",$ComboBoxInstance3, $Down1) ;Sets display#3 "Disconnect this display"
sleep($Timer2 )
ControlClick($ScreenRes1, "",$ButtonInstance4) ;Clicks "OK" Button
Sleep($Timer2 )
WinActive($DisplaySettings1) ;Waits for display settings screen
Sleep($Timer2 )
ControlClick($DisplaySettings1, "",$ButtonInstance1) ;Clicks Keep button
Exit



Case $Monitor1
;Disable HDTV and enable Monitor (HP w1907)
Run($ScreenResScreen1)
Sleep(500)
WinSetTrans($ScreenRes1, "", 0)
Sleep($Timer2)
ControlSend($ScreenRes1, "",$ComboBoxInstance3, $Down1)
Sleep($Timer2)
ControlSend($ScreenRes1, "",$ComboBoxInstance1, $Down1)
Sleep($Timer2)
ControlSend($ScreenRes1, "",$ComboBoxInstance1, $Down1)
Sleep($Timer2)
ControlSend($ScreenRes1, "",$ComboBoxInstance3, $Up1)
Sleep($Timer2)
ControlClick($ScreenRes1, "",$ButtonInstance4)
Sleep($Timer2)
WinActive($DisplaySettings1)
Sleep($Timer2)
ControlClick($DisplaySettings1, "",$ButtonInstance1) ;Clicks Keep button

Exit

EndSwitch
WEnd
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...