Sign in to follow this  
Followers 0
Milan158

Active windows changing script

27 posts in this topic

Hi, I'am new here. Just to know if AutoIt could resolve my issue:

I need a script for switching between certain windows, just like does ALT+TAB. Each window in this case would be a Firefox in separate window. Basically no other windows will be open, only those to be viewed one by one - with certain (30 seconds) duration.

Doable?

Many thanks in advance!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@Milan158 - Yes

 

Edit: Looking for a little more explanation? So are we :)

The more you can provide on what you're trying to accomplish, and what you have tried on your own, will help us help you. What is the end goal, why do you need to switch windows every 30 seconds. And are they separate windows or tabs?

Edited by JLogan3o13

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Hi, we have an application called Messenger which shows status of several milling machines. This is displayed on a monitor hanging on the workshop wall. But when all machines should be shown, the details are no more visible. The group wiev was OK for 4 machines max but now we have 7.

The Messenger runs on a dedicated PC, and needs only a browser. The idea is to open a separate windows (or tabs) for each machine and have a script to change the windows in a circle after some time.

My effort in this case was to watch the Youtube AutoIt tutotial (18 parts) - not bad, but haven't found a hint for my issue.

Glad to hear that AIT is capable to do this. Some hints would be helpful. Or maybe the whole script,  I guess the code will hardly contain more than 10 rows.

I can create reciprocally an excel macro if somebody needs - here in the Czech Republic I was quite an active contributor into the Excel forum

Share this post


Link to post
Share on other sites

Have a look in the helpfile: 

Quote

WinActivate

Activates (gives focus to) a window.

 

Share this post


Link to post
Share on other sites

Red but still haven't moved further. Don't know how can I find out the window titles? The definition link does not helped much either - just like the examples.

Would it be possible to identify the windows using a index number? What is the syntax?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Where is the problem? With Winlist you can get the handles from all Windows. With this little

#include <Array.au3>
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

$aWL=WinList('Firefox')
_ArrayDisplay($aWL)

you get all Windows with Firefox in title. With the hwnd (displayed in Col 1) yo can activate a window by using WinActivate. This script 

#include <Array.au3>
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

$aWL=WinList('Firefox')
_ArrayDisplay($aWL)

for $i=1 to $aWL[0][0]
    WinActivate($aWL[$i][1])
    MsgBox(16,'Just activated',$aWL[$i][0])
Next

shows activates all windows with Firefox in title in a loop. After a window is shown you have to click the MsgBox before next window get activated.

Edited by AutoBert

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@Milan158,

welcome to AutoIt and to the forum!

adding to what @AutoBert said: the script will exit after activating each window one time. you need to wrap the entire thing in a loop - and make the WinList() the first operation in the loop, so when you close or open new window, the list will be updated. so, when you remove the _ArrayDisplay() and MsgBox() which are used to demonstrate what you get, put a better criteria to detect the Firefox browser windows, and add the sleep, you get:

P.S. for your first visit, consider yourself welcomed with a complete working script. don't expect that as a habit; next time, you are expected to show some effort on your own before posting :-)

 
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
While True
    $aWL = WinList(" - Mozilla Firefox")
    For $i = 1 To $aWL[0][0]
        WinActivate($aWL[$i][1])
        Sleep(30000)
    Next
WEnd

 

Edited by orbs

Share this post


Link to post
Share on other sites

@orbs: If you are already presenting the solution, also using the Silver Tablet and put the bill Discreet bib.  :)(translated with Google-Api for testing)

 

@Milan158: If you want a key for terminating:

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate")

While True
    $aWL = WinList(" - Mozilla Firefox")
    For $i = 1 To $aWL[0][0]
        WinActivate($aWL[$i][1])
        Sleep(30000)
    Next
WEnd

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Share this post


Link to post
Share on other sites

Thank you guys. What am i doing wrong?

Share this post


Link to post
Share on other sites

Here is the screen

MilanScreen1.png

Share this post


Link to post
Share on other sites
44 minutes ago, Milan158 said:

Thank you guys. What am i doing wrong?

 

Using the example scipt, which show's the founded Windows and not reading in helpfile about used funcs.

 

Use the last script i posted in #8

Share this post


Link to post
Share on other sites

Many thanks and very appreciated!

Heureka it works !  The windows didn't change regularly though - some of them were displayed twice loner then the interval. Then I put the WinList before the loop and now it works as desired - of course without the updating luxury of # windows.

I have to retrospectivelly study the syntax used in this environment. Spent more than hour looking for AutoIT manual or book in my native language but haven't found anything in Computerpress etc. No forum, nothing. Strange.

Before I will be able to utilize the help, I need some "human" guidance. Could u recommend me a good manual, please ?

Thanks again!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I build in to update the WinList by F8:

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate")     ;ESC terminates the script
HotKeySet("{F8}", "Restart")        ;F8 causes an Update of the FF-windows in max. 30 sec.  

$aWL = WinList(" - Mozilla Firefox")

While True
    For $i = 1 To $aWL[0][0]
        If Not IsArray($aWL) Then ExitLoop  ;Restarted
        if WinActivate($aWL[$i][1]) Then    ;only in existing windows 
            Sleep(30000)
        Else    ;window is closed meanwhile
            ContinueLoop
        EndIf
    Next
    ;ConsoleWrite('Winlist Update'&@CRLF)
    $aWL = WinList(" - Mozilla Firefox")
WEnd

Func Restart()
    $aWL='' 
    ;ConsoleWrite('Restarted'&@CRLF)
EndFunc

Func Terminate()
    Exit
EndFunc   ;==>Terminate

the codehiglighting seems to be damaged.

Edited by AutoBert

Share this post


Link to post
Share on other sites
12 hours ago, Milan158 said:

I have to retrospectivelly study the syntax used in this environment.

that's why you were given the code, it's quite simple and demonstrates common practices and abilities of AutoIt. use it to learn it.

12 hours ago, Milan158 said:

Spent more than hour looking for AutoIT manual or book in my native language but haven't found anything in Computerpress etc. No forum, nothing. Strange.

don't look up programming books for AutoIt in any language other than English. the greatness of AutoIt, to my taste, is that it is written in English, not in Computerish, like other languages. it makes it very easy to learn and apply.

and... no forum? really? :)

@AutoBert,

10 hours ago, AutoBert said:

If Not IsArray($aWL) Then ExitLoop  ;Restarted or no FF-wondows

note that if no windows found, WinList still returns an array, although an empty one. an indicator that no windows found would be if $aWL[0][0]=0.

also, you are calling WinList twice - once before everything begins, and one at the end of each pass. wouldn't it be more correct to call it once at the beginning of each pass (i.e. right after the While True line)?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

43 minutes ago, orbs said:

really? :)

@AutoBert,

11 hours ago, AutoBert said:

If Not IsArray($aWL) Then ExitLoop  ;Restarted or no FF-wondows

note that if no windows found, WinList still returns an array, although an empty one. an indicator that no windows found would be if $aWL[0][0]=0.

this inserted Func: 

Func Restart()
    $aWL='' 
    ;ConsoleWrite('Restarted'&@CRLF)
EndFunc

is used for error producing this error if user clicks F8. And after the For...Next loop is exited i populate $aWL again.

But you are right: my comment for this line is wrong, just edited.

Edited by AutoBert

Share this post


Link to post
Share on other sites

The intervals were not equal,  some windows appear twice (or even 3 times) longer.  Had to remove the WinList from the loop. The the F8 functionality is lost, but it is not a problem. Seems like an easy thing but is not.

When I change the string from  - Mozilla Firefox into - Internet Explorer, then the behavior is strange: new empty Tabs are added into the IE... 

Share this post


Link to post
Share on other sites

sorry, didn't fully understand the meaning Report post. In my age of 53 need a bit more time :)

 

Share this post


Link to post
Share on other sites

Wanted to add: I can explain why some windows appeared twice - after the array was refreshed again in random order, it could happen the same window pop up again. But this does not explain why it happened 3 times in a row. No doubt, I have witnessed it.  Mystery...

 

Share this post


Link to post
Share on other sites

@Milan158,

would you mind posting the code you are currently using? to make sure we are all on the same page here.

if you are so anxious to solve the "mystery", you can add some logging to the script. but if you keep closing and opening Firefox windows, then irregularities are expected; if you are not, then (when you are at a stable state) irregularities should not happen anyways. so is this really necessary?

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