Sign in to follow this  
Followers 0
picea892

Attach monitor and move position

6 posts in this topic

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.

post-45064-12512046863532_thumb.jpg

Share this post


Link to post
Share on other sites



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.

#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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

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

Share this post


Link to post
Share on other sites

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]")

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by picea892

Share this post


Link to post
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
Sign in to follow this  
Followers 0