Jump to content
Sign in to follow this  
Akarillon

[Solved]Change active display screen

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!

Share this post


Link to post
Share on other sites

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

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By joseLB
      Hi
      This piece of code creates and reads OK a key at  "HKEY_LOCAL_MACHINE" and can be changed for a key at "HKEY_CURRENT_USER"
      $sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav", "REG_SZ", "5555") MsgBox(4096,"wrote", $sta &@cr& @error) $zz= RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav") MsgBox(4096,"readed","="&$zz &@cr& @error) Exit With  HKEY_CURRENT_USER, in RegEdit we can see the created key, and we can create the key by hand/RegEdit and everything Works OK.
      At  HKEY_LOCAL_MACHINE we can´t see the created key above  thru RegEdit, but it Works (even not seeing, I can read). But  if I create "by hand"/RegEdit  the key,  it can´t read it with   $zz= RegRead  ("HKEY_LOCAL_MACHINE.... above.
      I´m the PC´s WIN.7 administrator. Even so I ran RegEdit as administrator and also the compiled AU3 and also plain. No changes.
      edit: even if Try   "HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", the same holds true.
      $sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", "REG_SZ", "4444") MsgBox(4096,"wrote", $sta &@cr& @error) $zz= RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav") MsgBox(4096,"readed","="&$zz &@cr& @error) Exit Seems that it creates this key at another place.... I can read the above value ("4444"), even after a boot, even the key not showing in regedit. And if I create it by hand key AAA/wav with a distinct value (666), t, it continues Reading the old value = 444.
      Thanks
      Jose
       
    • By nacerbaaziz
      good morning everybody.
      today i liked to share an small example with you
      which it an function to read the registry values as an array
      the result array is 2d array witch
      $a_array[n][0] = value name
      $a_array[n][1] = value Data
      $a_array[0][0] = values count
      here's the function

      #include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local $a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then     MsgBox(16, "error", @error)     Exit EndIf _ArrayDisplay($a_array) Func _RegReadToArray($s_RegKey)     Local $a_KeySplitInfo = StringSplit($s_RegKey, "\\", 2)     If UBound($a_KeySplitInfo) <= 1 Then         $a_KeySplitInfo = StringSplit($s_RegKey, "\", 2)         If UBound($a_KeySplitInfo) <= 1 Then Return (1, 1, 0)     EndIf     Local $H_KeyInfo = "", $s_RegKeyInfo = ""     Switch $a_KeySplitInfo[0]         Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64"             $H_KeyInfo = $HKEY_LOCAL_MACHINE         Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64"             $H_KeyInfo = $HKEY_CURRENT_USER         Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64"             $H_KeyInfo = $HKEY_CLASSES_ROOT         Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64"             $H_KeyInfo = $HKEY_USERS         Case Else             Return SetError(2, 2, 0)     EndSwitch     _ArrayDelete($a_KeySplitInfo, 0)     $s_RegKeyInfo = _ArrayToString($a_KeySplitInfo, "\")     Local $H_KeyInfoOpen = _WinAPI_RegOpenKey($H_KeyInfo, $s_RegKeyInfo, $KEY_READ)     Local $A_KeyInfo = _WinAPI_RegQueryInfoKey($H_KeyInfoOpen)     If @error Then Return SetError(1, 1, 0)     _WinAPI_RegCloseKey($H_KeyInfoOpen)     Local $A_RegVal[$A_KeyInfo[2] + 1][2]     Local $iV = 1, $s_RegRead = ""     While 1         $s_RegVal = RegEnumVal($s_RegKey, $iV)         If @error <> 0 Then ExitLoop         $s_RegRead = RegRead($s_RegKey, $s_RegVal)         If Not (@error) Then             $A_RegVal[$iV][0] = $s_RegVal             $A_RegVal[$iV][1] = $s_RegRead         EndIf         $iV += 1     WEnd     $A_RegVal[0][0] = UBound($A_RegVal) - 1     If $A_RegVal[0][0] >= 1 Then         Return $A_RegVal     Else         Return SetError(3, 3, 0)     EndIf EndFunc   ;==>_RegReadToArray
      i hope you benefit from it
      with my greetings
    • 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
    • By TheDcoder
      Hello, it has been a long time since I have posted here
      I am working on an AutoIt project where I need to enable to user to interactively choose any point or coordinate on the screen... something like a big overlay where the user can click anywhere on the screen to select that point. @UEZ's screenshot tool may have something similar to what I need:
      I just checked the source code for the tool and I see that the Mark_Area function has a part in selecting the area to screenshot, I tried to figure out how it works but it is simply too complex and long...
      So I was wondering if there were any examples of interactively selecting points on a screen? Maybe an UDF that I can just use in my script to make the whole thing a matter of adding few lines
      Thank you for the replies in advance!
    • By copyleft
      I've looked at a bunch of SetACL examples on this site and none seem to be able to convert this batch script into a working AutoIt script.
      BATCH
      @echo off "%~dp0setacl.exe" -on "HKEY_CLASSES_ROOT\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr n:administrators >nul 2>nul "%~dp0setacl.exe" -on "HKEY_CLASSES_ROOT\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn ace -ace "n:administrators;p:full" >nul 2>nul Reg.exe add "HKCR\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" /ve /t REG_EXPAND_SZ /d "C:\My.ico" /f NON-WORKING AUTOIT
      RunWait('setacl.exe "HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr "n:administrators"') RunWait('setacl.exe "HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr "n:administrators;p:full"') RegWrite('HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon', '','REG_EXPAND_SZ','C:\Windows\My.ico') Any ideas on what I'm doing wrong?
       
×
×
  • Create New...