Jump to content
Sign in to follow this  
jblas

Adjust Auto cycle open windows

Recommended Posts

Hi, I'm trying to alter a script that I found here that maximizes then cycles through open windows. It works really well. The only issue that I have with it is that while testing with 4 seperate Excel 2016 instances, it cycles forwards and then back through the windows so that the first window is displayed for twice the time after it's initial call and the last window shows for twice the time before cycling back down.

For example,

Set the script to cycle every 10 seconds.

Get all the windows up and minimized and then run the script.

Window#1 will come up for 10 seconds then move on to window#2 for 10 seconds then on to window#3 for 10 seconds then to window#4 for 20 seconds then back to window#3 for 10 seconds then back to window#2 for 10 seconds and then back to window#1, this time for 20 seconds before cycling back up through the windows again.

So the script is bouncing up then down through the windows and counting the 1st and last windows for two cycles after the initial call of window#1.

I don't know much when it comes to scripting in general so I'm way over my head in trying to get this script to do what I need. I am not seeing why it is cycling forwards then back instead of just forwards like I expected. I thought it would just continue on from windows#4 to windows#1 and keep going forwards and not bounce back and forth.

The code I'm refering to is found here: 

It was posted by user: picea892

I'm going to be researching and going through tutorials for autoit to see if I can't educate myself enough to figure this out but in the meantime if someone here can point me in the right direction, I would greatly aprreciate it.

Regards,

jblas

 

Share this post


Link to post
Share on other sites
#include <array.au3>
#include <Winapi.au3>
#include <Process.au3>
HotKeySet('{END}', 'Leave')
;=============================================================================
while 1
cycler()
WEnd
;=============================================================================
func cycler()
$winlist=_getwinlist()
for $i= 1 to $winlist[0][1]
    ToolTip('Count - '&$i&' - '&$winlist[$i][1])
    WinSetState($winlist[$i][2],"",@SW_MAXIMIZE)
    WinActivate($winlist[$i][2],"")
    sleep(1000)
Next
EndFunc
;=============================================================================
func _getwinlist ()
Local $sExclude_List = "|Start[CL:102939]|Start|Desktop|Start Menu[CL:102938]|taskbar|iconwin|desktop[CL:102937]|Program Manager|taskbar|Menu|Save As|Drag|maincontext|context|"
Local $sExclude_class = "|tooltips_class32|gdkWindowToplevel|gdkWindowTempShadow|TaskSwitcherWnd|gdkWindowTemp|bosa_sdm_Microsoft Office Word 11.0|MsoCommandBarPopup|MsoCommandBarShadow|NUIDialog|CallTip|ThumbnailClass|#32770|Desktop User Picture|OfficeTooltip|"
Local $Listit
Local $aWinList = WinList()
dim $Listit[$aWinList[0][0]][5]
;Count windows
For $i = 1 To $aWinList[0][0]
;Only display visible windows that have a title
    If $aWinList[$i][0] = "" Or Not BitAND(WinGetState($aWinList[$i][1]), 2) Then ContinueLoop
;Add to array all win titles that are not in the exclude list
        $class = _WinAPI_GetClassName($aWinList[$i][1])
    If Not StringInStr($sExclude_List, "|" & $aWinList[$i][0] & "|") and Not StringInStr($sExclude_class, "|" & $class & "|") Then
        $Listit[0][1]=$Listit[0][1]+1
        $Listit[$Listit[0][1]][0]= _ProcessGetName (WinGetProcess($aWinList[$i][1]))
        $Listit[$Listit[0][1]][1]= $aWinList[$i][0]
        $Listit[$Listit[0][1]][2]= $aWinList[$i][1]
        $Listit[$Listit[0][1]][3]= $class
    EndIf
Next
_ArraySort($Listit, 1, 1)
;_ArrayDisplay($Listit)
ReDim $Listit[$Listit[0][1]+1][5]
return $Listit
EndFunc
;=============================================================================
Func Leave()
    Exit
EndFunc
;=============================================================================

The issue was due to the winlist, and the way it sorts the windows, so it seems like the last window then becomes the first in the winlist function, so there you have it, the 

_ArraySort($Listit, 1, 1)

sorts it the same way so regardless of the order when you call winlist, it gets ordered the same way and it becomes a true cycle.

The sort has to start in the index 1, because the index 0 has the window count.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

That makes sense, I really appreciate your help. I also like the addition of the leave function, that was something I was going to implement but hadn't started looking into how.  I tried it out and it works perfectly with 3 windows as long as they are started in reverse order of the order in which you wish to cycle through them. So if I start window#3 then window#2 then window#1 then when we run the script, the first window to display is #1 then #2 then #3 and back to #1, #2, #3 and so on... I tried adding a fourth window to the mix and ended up with it doing the following.

Again, I start the windows in reverse order, 4 3 2 1, before minimizing them and running the script. Here is the order in which they cycle through:

#2, #1, #4, #3, #1, #2, #3, #4 then back to #2, #1, #4... and continues repeating .

I've spend a fair amount of time working on understanding how the array works, reading through the array section in the Wiki, but haven't figured out what is going yet. I tried putting in the following code in a couple different areas to see if I can figure out the flow.

ConsoleWrite("$aWinlist[" & $i & "]:=" & $aWinlist[$i] &  @LF)

But that just throws this error in the few places I have tried inserting it:

image.png.c217ca33bd41a60c4c8e8df7160d9766.png

I'm wondering if it would work fine on Windows 7. I haven't tried it on that yet as I'm working in Windows 10. And In Windows 10 it has another issue that doesn't happen verry often so I don't have it well documented yet. In Windows 10 when I run the script it sometimes will bring up the Windows Settings after pulling up the first two or three windows. All of a sudden the Windows Settings page is in the mix. At first I thought that maybe I had it minimized but it has happend 5 or 6 times in the corse of working on this. I'm gona call it a day and see if a fresh start tomorrow will help. Thank you again for your help with this.

Regards,

Jblas

 

Share this post


Link to post
Share on other sites

Can you test this again?

#include <array.au3>
#include <Winapi.au3>
#include <Process.au3>
HotKeySet('{END}', 'Leave')
;=============================================================================
Global $sExclude_List = "|Start[CL:102939]|Start|Desktop|Start Menu[CL:102938]|taskbar|iconwin|desktop[CL:102937]|Program Manager|taskbar|Menu|Save As|Drag|maincontext|context|"
Global $sExclude_class = "|tooltips_class32|gdkWindowToplevel|gdkWindowTempShadow|TaskSwitcherWnd|gdkWindowTemp|bosa_sdm_Microsoft Office Word 11.0|MsoCommandBarPopup|MsoCommandBarShadow|NUIDialog|CallTip|ThumbnailClass|#32770|Desktop User Picture|OfficeTooltip|"
Global $Listit, $aWinList, $SectNames
;=============================================================================
while 1
cycler()
_ArrayDisplay($Listit)
for $i= 1 to $Listit[0][1]
    ToolTip('Count - '&$i&' - '&$Listit[$i][1])
   ;WinSetState($Listit[$i][1],"",@SW_MAXIMIZE)
    WinActivate($Listit[$i][1],"")
    sleep(1000)
Next
WEnd
;=============================================================================
func cycler()
$aWinList = WinList()
_ArraySort($aWinList, -1, 1, -1, 0)
dim $Listit[$aWinList[0][0]][4]
For $i = 1 To $aWinList[0][0]
    If $aWinList[$i][0] = "" Or Not BitAND(WinGetState($aWinList[$i][1]), 2) Then ContinueLoop
        $class = _WinAPI_GetClassName($aWinList[$i][1])
    If Not StringInStr($sExclude_List, "|" & $aWinList[$i][0] & "|") and Not StringInStr($sExclude_class, "|" & $class & "|") Then
        $Listit[0][1]=$Listit[0][1]+1
        $Listit[$Listit[0][1]][0]= _ProcessGetName (WinGetProcess($aWinList[$i][1]))
        $Listit[$Listit[0][1]][1]= $aWinList[$i][0]
        $Listit[$Listit[0][1]][2]= $aWinList[$i][1]
        $Listit[$Listit[0][1]][3]= $class
    EndIf
Next
EndFunc
;=============================================================================
Func Leave()
    Exit
EndFunc
;=============================================================================

 


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
4 hours ago, IAMK said:

@jblas I'm just having a guess here, but @LF is probably for Linux and @CRLF is for windows.

@LF is just a Line Feed, the @CRLF is a Carriage Return + Line Feed.

The error is due to the call of an array item where there isn't one.

Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Thanks @careca! That helps having the _ArrayDisplay in there. It shows that sometimes even when I don't have the Windows 10 Settings window showing on the taskbar that it is still running in the background. Even if the settings window isn't displayed in the rotation, it does show the last window displayed for extra time due what it detects as windows in Row1 and 2 below.

image.png.b05c5acf401cdf1bbcdd4fcc8ee63303.png

Now that I'm aware of that,  I can just use taskmanager to kill Systemsettings.exe before starting the script and it gets rid of the extra time taken by both of the erroneously detected Row 1 and Row 2 windows shown above. I've tested the new script out and it is working for 4 or even 6 windows. I haven't tried more than that yet.

The only issue I have found with it is that it is cycling through in the reverse order of what I need. It does that regardless of the order I start the maps in. The sort takes the windows titles (file names in my case) into account. So if I start the files named file1, file2, file3 and file4 in any order, it will always dislplay file4 first then file3 then file2 then file1. I can rename the files so that they are named in reverse order and that will then display them in the order that I need but...  I've tried replacing "_ArraySort($aWinList, -1, 1, -1, 0)" with "_ArraySort($aWinList, 1, 1)" on line 23 and changing various zeros to ones or vise versa in that and other areas. Thus far I haven't figured out what will fix the sort .

I'm done for the day. I'll keep banging away on this again tomorrow. Thanks again for taking the time to help with this.

Regards,

jblas

Share this post


Link to post
Share on other sites

As a side note, you could include those exe's in the exlusion list, no need to close the processes.

As for the sort, i think you're on the right path, what about _ArraySort($aWinList, 1, 1, -1, 0)?


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Thank you, I'd like to think that I would figured out at some point that I could just add Settings to the exclude list to remove those detected windows but... :)

I had already tried the  _ArraySort($aWinList, 1, 1, -1, 0) and other combinations of zeros and ones. I finally got a clue and looked up the info on the _ArraySort() and found this info:

image.png.eb060ef25b24835082d9a48153935af4.png

So from what I'm understanding, The $iDescending parameter is the first parameter and thus changing it from 1 to 0 should fix the sort for me.

After changing from _ArraySort($aWinList, -1, 1, -1, 0)  to  _ArraySort($aWinList, 0, 1 ,-1, 0), the sort is working the way I want it to. I then omitted the last two parameters, _ArraySort($aWinList, 0, 1)  and tested it and it works the same way without them. I assume that they are not needed then? 

I'm going to work on adding a simple GUI and post back what I come up with.  

Thank you @careca for all your help with this. I probably wouldn't have figured out a script, that would work for my application, off of @picea892's post for weeks if left on my own.

 

 

 

 

Share this post


Link to post
Share on other sites

Why are you using -1 in the parameters for _ArraySort?

Also, any parameter listed in square brackets are optional, and the value shown in the description is what it is set to unless you change it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I guess that was wrong on my part, i see now that it should've been 0. The only reason i included those parameters was because i was testing out some, and then didn't bother to just remove them, figured wouldn't make a difference.

Quote

I assume that they are not needed then?

Correct.

Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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.

×
×
  • Create New...