Jump to content

Small (working) script cleanup request


NaX
 Share

Recommended Posts

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

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...