picea892 Posted August 25, 2009 Share Posted August 25, 2009 Every time when I attach my laptop to my monitor I have to change the display settings. I have to "attach" the monitor then go to Display Properties - Settings and drag and drop the monitors to look like this. This is starting to annoy me and I want to automate this. Can someone help me find a way? I'd rather not use sendkeys, but if I must I will. Appreciate the help. Link to comment Share on other sites More sharing options...
Bowmore Posted August 25, 2009 Share Posted August 25, 2009 Every time when I attach my laptop to my monitor I have to change the display settings. I have to "attach" the monitor then go to Display Properties - Settings and drag and drop the monitors to look like this. This is starting to annoy me and I want to automate this. Can someone help me find a way? I'd rather not use sendkeys, but if I must I will. Appreciate the help. As they say on a famous UK tV program, Here's one I made earlier. expandcollapse popup#cs Introduction Script Name:Dual Screen Setup Purpose:Automate switching laptop to dual screen mode #ce #Region ### Set Options Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 2) Opt("TrayIconDebug", 1) #EndRegion ### Set Options #Region Includes #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <StatusBarConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #EndRegion Includes Global $aWinPos = WinGetPos("Program Manager") If $aWinPos[2] < 1500 Then Send("{LWINDOWN}d{LWINUP}") Opt("MouseCoordMode", 0) Sleep(1000) MouseMove((@DesktopWidth / 2), (@DesktopHeight / 2), 25) MouseClick("left") MouseClick("right") Opt("MouseCoordMode", 2) Sleep(500) Send("{UP}") Sleep(100) Send("{ENTER}") WinWait("Display Properties", "") If Not WinActive("Display Properties", "") Then WinActivate("Display Properties", "") WinWaitActive("Display Properties", "") WinWait("Display Properties", "") If Not WinActive("Display Properties", "") Then WinActivate("Display Properties", "") WinWaitActive("Display Properties", "") ControlClick("Display Properties", "", "[CLASS:SysTabControl32; INSTANCE:1]", "left", 1, 272, 11) MouseMove(250, 125) MouseDown("left") MouseMove(70, 130, 25) MouseUp("left") If WinWait("Monitor # 2", "The monitor you have", 2) Then If Not WinActive("Monitor # 2", "The monitor you have") Then WinActivate("Monitor # 2", "The monitor you have") WinWaitActive("Monitor # 2", "The monitor you have") ControlClick("Monitor # 2", "The monitor you have", 6) EndIf ControlClick("Display Properties", "", "[CLASS:Button; INSTANCE:8]") Else Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) Send("{LWINDOWN}d{LWINUP}") Opt("MouseCoordMode", 2) Sleep(1000) MouseMove((@DesktopWidth / 2), (@DesktopHeight / 2), 25) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : (@DesktopHeight / 2) = ' & (@DesktopHeight / 2) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : (@DesktopWidth / 2) = ' & (@DesktopWidth / 2) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console MouseClick("left") MouseClick("right") Opt("MouseCoordMode", 2) Sleep(500) Send("{UP}") Sleep(100) Send("{ENTER}") WinWait("Display Properties", "") If Not WinActive("Display Properties", "") Then WinActivate("Display Properties", "") WinWaitActive("Display Properties", "") ControlClick("Display Properties", "", "[CLASS:SysTabControl32; INSTANCE:1]", "left", 1, 272, 11) Sleep(500) MouseClick("left", 125, 130, 1, 25) Sleep(500) ControlClick("Display Properties", "", "[CLASS:Button; INSTANCE:4]") Sleep(500) ControlClick("Display Properties", "", "[CLASS:Button; INSTANCE:8]") Sleep(5000) Send("{LWINDOWN}d{LWINUP}") EndIf Exit "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
picea892 Posted August 25, 2009 Author Share Posted August 25, 2009 I hoped there was a DLLcall or something. Maybe someone will provide.... I can get to the display settings by running this control desk.cpl,,@Settings Then from there I can use your controlclick, mouseclick technique. This is a workable option. Thank you for providing....and so fast too. Link to comment Share on other sites More sharing options...
Bowmore Posted August 25, 2009 Share Posted August 25, 2009 I hoped there was a DLLcall or something. Maybe someone will provide....I can get to the display settings by running thiscontrol desk.cpl,,@SettingsThen from there I can use your controlclick, mouseclick technique. This is a workable option.Thank you for providing....and so fast too.I used my script almost every day for over a year without any problems. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
picea892 Posted August 25, 2009 Author Share Posted August 25, 2009 Actually it is quite a bit faster and less intrusive than I thought. Everybody has there monitors slightly different so I couldn't use yours exactly as it, but I got me started. Below is what I have so far. It's starting to work. I'll keep tweaking over the next few days and get it right. Thanks again Picea Opt("MouseCoordMode", 2) run("control desk.cpl,,@Settings") WinWaitActive("Display Properties","") MouseClickDrag("left", 225, 130, 100, 150) ControlClick("Monitor # 2","","[CLASS:Button; INSTANCE:1]") ControlClick("Display Properties","","[CLASS:Button; INSTANCE:10]") ControlClick("Display Properties","","[CLASS:Button; INSTANCE:8]") Link to comment Share on other sites More sharing options...
picea892 Posted August 25, 2009 Author Share Posted August 25, 2009 (edited) Hi way out of my league here. But found this DLLcall and think it is what I need if I can get it to work. Do I have it set up right? I'm not exactly sure how to get the monitor but have tried two ways. The one in the example and $sMonitorName = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY", "1") $s_Display = "\\.\Display" & "2" DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "str", "Null", "hwnd", 0, "dword", "CDS_SET_PRIMARY", "lparam", 0) http://msdn.microsoft.com/en-us/library/dd183413(VS.85).aspx Edited August 25, 2009 by picea892 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now