Jump to content

[Solved]Change active display screen


 Share

Recommended Posts

I am trying to make a script that changes the active display screen.

I got a setup with 3 screens and can only have 2 active screens at the same time, so I want to automate the process by making a script for it.

Screen 1(Main) and 2(Extended) are my main screens.

I also got a third screen that I use for watching movies and such.

I've tried searching both the forum and google for relevant problems, but I can't seem to find anything.

Also tried looking for the display settings in the registry, but gave up searching without any idea what to look for.

Do you guys got any tips?

Regards,

Akarillon

Edited by Akarillon

Challenge accepted!

Link to comment
Share on other sites

Link to comment
Share on other sites

Maybe I didn't make myself clear.

I want to change the active screen, not a window.

At the moment I use the Screen Resolution setting like the screenshot shown in the image.

But since I am doing this 2-3 times a day I really want to automate it.

Posted Image

Challenge accepted!

Link to comment
Share on other sites

I had a quick look at the screen resoulation, and it appears to be compatable with controlclick.

So you could make a script that works like this.

Lauch Screen Res Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl")

Hide the window with WinSetTrans

The controlclick 3 Screen

Controlsend 5 tabs "so the focus is over Mutiplay displays drop down"

Controlsend down so its on extend displays

controlsend enter.

Then same again for the screen you want to disconnect

then controlclick the OK button

close the window

finished :)

Link to comment
Share on other sites

Thanks man! :P

Did not think about that.

I was a little bit slow replying, but was busy during the weekend.

Here's the script I got working.

Did not find any way to detect what screen was active so added a 2 button activation popup.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=..Compilex64ScreenResolution.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include 
#include 
#include 
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 258, 114, 401, 181)
$Button1 = GUICtrlCreateButton("Gaming", 32, 24, 75, 65)
$Button2 = GUICtrlCreateButton("Bed", 152, 24, 75, 65)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Button1
Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl")
Sleep(500)
WinSetTrans("Screen Resolution", "", 0)
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{UP}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{DOWN}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{DOWN}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:1]", "{UP}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:1]", "{UP}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{UP}")
Sleep(150)
ControlClick("Screen Resolution", "", "[CLASS:Button; INSTANCE:4]")
Sleep(500)
Send("{LEFT}")
Sleep(150)
Send("{ENTER}")
Exit

Case $Button2
Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl")
Sleep(500)
WinSetTrans("Screen Resolution", "", 0)
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{UP}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:1]", "{DOWN}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{DOWN}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:1]", "{UP}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{DOWN}")
Sleep(150)
ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:3]", "{DOWN}")
Sleep(150)
ControlClick("Screen Resolution", "", "[CLASS:Button; INSTANCE:4]")
Sleep(500)
Send("{LEFT}")
Sleep(150)
Send("{ENTER}")
Exit

EndSwitch
WEnd

Challenge accepted!

Link to comment
Share on other sites

As you shown an effort instead i just did it for u ^^

ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:1]", "{Down 2}") ;From my test it always starts on screen 1, so down 2 for screen 3.

$ScreenText=WinGetText("Screen Resolution")
If StringInStr($ScreenText, "Extend desktop to this display", 1, 1) Then
ConsoleWrite("Screen 3 is Enabled. Run Disable Screen 3 and Enable Screen 1 Code" & @CRLF)
Else
ConsoleWrite("Screen 3 is Disabled. Run Disable Screen 1 and Enable Screen 3 Code" & @CRLF)
EndIf

Enjoy :D

Oh yea, make sure you read the spoiler as well. Its kinda important.

Ok So i had an idea on how you could automaicly detect which is active or not :)

So in your picture for example

Controlclick Screen 3

On the Mutiplie Displays it will say "extend desktop to this display" or "disconnect this display". You can get this info from WIngetText on the combo box.

So u get the list, if "Disonnect" is there then the screen is not on. Else it is and run the other one :)

I noticed after i had written how to do it, your post is kinda game-related. Ironic the first time i help someone and without knowing it was to assist with making gaming easier ^^. Make sure you read the forum rules so in the furture you do not get in any trouble.

http://www.autoitscript.com/forum/forum-2/announcement-15-forum-rules-7-nov-2012/

Now i defile anyone to say this topic is against the rules *apart from like Melba or any else in power who can defile me without a second glance ^^* It doesnt launch, automate or interact with a game or server. Just happens to have a button labeled "Gaming" :P

Edited by IanN1990
Link to comment
Share on other sites

As you shown an effort instead i just did it for u ^^

ControlSend("Screen Resolution", "", "[CLASS:ComboBox; INSTANCE:1]", "{Down 2}") ;From my test it always starts on screen 1, so down 2 for screen 3.

$ScreenText=WinGetText("Screen Resolution")
If StringInStr($ScreenText, "Extend desktop to this display", 1, 1) Then
ConsoleWrite("Screen 3 is Enabled. Run Disable Screen 3 and Enable Screen 1 Code" & @CRLF)
Else
ConsoleWrite("Screen 3 is Disabled. Run Disable Screen 1 and Enable Screen 3 Code" & @CRLF)
EndIf

Enjoy :D

Oh yea, make sure you read the spoiler as well. Its kinda important.

Ok So i had an idea on how you could automaicly detect which is active or not :)

So in your picture for example

Controlclick Screen 3

On the Mutiplie Displays it will say "extend desktop to this display" or "disconnect this display". You can get this info from WIngetText on the combo box.

So u get the list, if "Disonnect" is there then the screen is not on. Else it is and run the other one :)

I noticed after i had written how to do it, your post is kinda game-related. Ironic the first time i help someone and without knowing it was to assist with making gaming easier ^^. Make sure you read the forum rules so in the furture you do not get in any trouble.

http://www.autoitscript.com/forum/forum-2/announcement-15-forum-rules-7-nov-2012/

Now i defile anyone to say this topic is against the rules *apart from like Melba or any else in power who can defile me without a second glance ^^* It doesnt launch, automate or interact with a game or server. Just happens to have a button labeled "Gaming" :P

Yea, that should work.

Thanks! :)

About the gaming tag.

The rule clearly states:" Launching, automation or script interaction with games or game servers, regardless of the game."

And I am not doing any of those.

The reason I wrote gaming on the button is because that is what I usually do.

I could change the name to "work".

Challenge accepted!

Link to comment
Share on other sites

  • 1 year later...

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

×
×
  • Create New...