NaX Posted August 20, 2012 Share Posted August 20, 2012 A small script that works to change between a single monitor (computer only) setup to an extended monitor (extend monitor). (pressing win+p then keying over was not efficient) essentially the script retrieves the state of my second monitor then sends the appropriate displayswitch command switch to toggle the monitor state I managed to make the script work (from other scripts) but it could be tighten up, hence the request hope this script is helpful for someone else #AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <WinAPI.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $aDevice, $i = 0, $text While 1 $aDevice = _WinAPI_EnumDisplayDevices("", 1) if BitAND($aDevice[3], 1) then Run("DisplaySwitch.exe /internal") if not BitAND($aDevice[3], 1) then Run("DisplaySwitch.exe /extend") ExitLoop WEnd EndFunc ;==>_Maintoggle monitors.au3 Link to comment Share on other sites More sharing options...
stormbreaker Posted August 20, 2012 Share Posted August 20, 2012 So, my dear Sodium Halide, what do you want? I really didn't get your question... if this is an Example script, probably you posted it in the wrong section... ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
water Posted August 20, 2012 Share Posted August 20, 2012 Sodium Halide? I think the OP just want's to make the code more efficient. I would suggest to use If/Then/Else and to remove the While/WEnd because the loop is executed only once when cause of the ExitLoop. #AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <WinAPI.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $aDevice = _WinAPI_EnumDisplayDevices("", 1) If BitAND($aDevice[3], 1) Then Run("DisplaySwitch.exe /internal") Else Run("DisplaySwitch.exe /extend") EndIf EndFunc ;==>_Main My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
stormbreaker Posted August 20, 2012 Share Posted August 20, 2012 i don't want to sound disrespectful, but 'hope this script is helpful for someone else' is what made me put that question. NaX - sodium halide. I'm just fond of chemistry. ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
NaX Posted August 21, 2012 Author Share Posted August 21, 2012 terribly sorry - my post was not the clearest yes, it is a request to clean up the code thank you water - I didn't know how to only execute the code once 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