Sign in to follow this  
Followers 0
NaX

Small (working) script cleanup request

5 posts in this topic

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 ;==>_Main

toggle monitors.au3

Share this post


Link to post
Share on other sites



:idiot: 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

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

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