Sign in to follow this  
Followers 0
Akarillon

[Solved]Change active display screen

9 posts in this topic

#1 ·  Posted (edited)

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!

Share this post


Link to post
Share on other sites



try this:

WinSetState("[CLASS:Notepad]", "", @SW_HIDE)
Sleep(3000)
WinSetState("[CLASS:Notepad]", "", @SW_SHOW)

it's that you need.

regards.

Share this post


Link to post
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!

Share this post


Link to post
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 :)

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
'i defile anyone' ROFL
1 person likes this

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

  • Similar Content

    • Skeletor
      By Skeletor
      MS Splash Screens
      The office 2016/17 office suite has made many people turn heads with its functions and especially their splash screen.
      I now present to you, the MS Style Splash Screen. For Rookies, Novices and anyone who wants a ready made splash screen for your gui application.

      You can now download it and also try it out yourself.
      You have three colors to choose from:
      Blue
      Red
      Green
      All three colours are from the famous programs.
      I also included the KODA form to you can have freedom with this splash screen.
      Note: the KODA form does not have the three colours as well as the correct blue. 

      Have fun and enjoy.
      Note:
      I will update the splash to add the automated 3 dots animation at a later stage. 
       
       
    • Skeletor
      By Skeletor
      Hi All,
      I know many newbies search for this feature.
      I decided to share this piece of code with everyone.
      Basically its a "splash screen" that has a transparent image.
      In a nutshell - Gui with a transparent gif.
      Enjoy...
      Download attachment....
       
      Splash Screen GUI.zip
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me
    • Stormgrade
      By Stormgrade
      Hello,
      I want to use the "_ChangeScreenResEx()" UDF for changing my display settings from 1680*1050 to 1280*800.
      When I use it the display change to 1280*800 but with Intel Drivers, Scaling option change : Maintain display Scaling become Center Image.

      Here my Main program
      #include <.\_ChangeResolutionEx.au3> Global $Config = @ScriptDir & "\ChangeResolution.ini" Global $aSection = IniReadSectionNames($Config) Global $Moniteur,$Largeur,$Hauteur,$Profondeur,$Refresh for $i = 1 to $aSection[0] Step 1 $Moniteur = Number($i) $Largeur = Number(IniRead($Config,$i,"Width","1680")) $Hauteur = Number(IniRead($Config,$i,"Height","1050")) $Profondeur = Number(IniRead($Config,$i,"Bits","32")) $Refresh = Number(IniRead($Config,$i,"Refresh","60")) _ChangeScreenResEx($Moniteur,$Largeur,$Hauteur,$Profondeur,$Refresh) Sleep(1000) Next  _ChangeScreenResEx()
      #include-once ;=============================================================================== ; Function Name: _ChangeScreenResEx() ; Description: Changes the current screen geometry, colour and refresh rate. ; Version: 1.0.0.0 ; Parameter(s): $i_DisplayNum - Display to change, starting at 1 ; $i_Width - Width of the desktop screen in pixels. (horizontal resolution) ; $i_Height - Height of the desktop screen in pixels. (vertical resolution) ; $i_BitsPP - Depth of the desktop screen in bits per pixel. ; $i_RefreshRate - Refresh rate of the desktop screen in hertz. ; Requirement(s): AutoIt Beta > 3.1 ; Return Value(s): On Success - Screen is adjusted, @ERROR = 0 ; On Failure - sets @ERROR = 1 ; Forum(s): ; Author(s): Original code - psandu.ro, PartyPooper ; Modifications - bobchernow ;=============================================================================== Func _ChangeScreenResEx($i_DisplayNum = 1, $i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) Local Const $DM_PELSWIDTH = 0x00080000 Local Const $DM_PELSHEIGHT = 0x00100000 Local Const $DM_BITSPERPEL = 0x00040000 Local Const $DM_DISPLAYFREQUENCY = 0x00400000 Local Const $CDS_TEST = 0x00000002 Local Const $CDS_UPDATEREGISTRY = 0x00000001 Local Const $DISP_CHANGE_RESTART = 1 Local Const $DISP_CHANGE_SUCCESSFUL = 0 Local Const $HWND_BROADCAST = 0xffff Local Const $WM_DISPLAYCHANGE = 0x007E If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth; default to current setting If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight; default to current setting If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth; default to current setting If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh; default to current setting Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]") Local $s_Display $s_Display = "\\.\Display" & $i_DisplayNum Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($DEVMODE)) If @error Then $B = 0 SetError(1) Return $B Else $B = $B[0] EndIf If $B <> 0 Then DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5) DllStructSetData($DEVMODE, 4, $i_Width, 2) DllStructSetData($DEVMODE, 4, $i_Height, 3) DllStructSetData($DEVMODE, 4, $i_BitsPP, 1) DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5) $B = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_TEST, "lparam", 0) If @error Then $B = -1 Else $B = $B[0] EndIf Select Case $B = $DISP_CHANGE_RESTART $DEVMODE = "" Return 2 Case $B = $DISP_CHANGE_SUCCESSFUL DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_UPDATEREGISTRY, "lparam", 0) DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" SetError(1) Return $B EndSelect EndIf EndFunc;==>_ChangeScreenResEx Any idea how to get around this problem ?
      thanks for your answer.
    • Simpel
      By Simpel
      Hi,
      I wondered why negative integers I wrote into registry (e.g. negative x-coordinates of a gui if using two monitors and the right one is the main one) wouldn't return right when reading. Now I know: it is saved as an unsigned integer (without algebraic sign). So here is a snippet that is changing unsigned to signed integer:
      Global Const $g_sRegKey = "HKEY_CURRENT_USER\Software\" & @ScriptName ; path to registry RegWrite($g_sRegKey, "Value", "REG_DWORD", -2147483647) ; write some negative integer into registry; -2147483647 highest possible negative integer , 2147483648 highest possible positive integer if talking of 32bit Local $sValue = RegRead($g_sRegKey, "Value") ; read out registry ConsoleWrite("Value: " & $sValue & @CRLF) ; show real value in console Local $sResult = _SignedInteger($sValue) ; change to signed value ConsoleWrite("Result: " & $sResult & @CRLF) ; and show it in console Func _SignedInteger($iUnsignedInteger) Local $iSignedInteger If $iUnsignedInteger > (2^31) Then ; then it means a negative integer $iSignedInteger = $iUnsignedInteger - (2^32) Else $iSignedInteger = $iUnsignedInteger EndIf Return $iSignedInteger EndFunc It took me some time to find out the problem and so I hope I can help somebody with this.
      Regards, Conrad