Jump to content
Sign in to follow this  
NaX

Small (working) script cleanup request

Recommended Posts

NaX

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
stormbreaker
: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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
stormbreaker

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
NaX

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  

×