itauto3 Posted January 17, 2019 Share Posted January 17, 2019 My counter counts from 0 on, if it finds any Notepad window opened, but it counts double (if 2 windows are opened), triple (if 3 windows are opened)..., instead of 1, 2, 3... Any suggestion? #include <Array.au3> $count = 0 While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) For $i=1 To $aWindows[0][0] $iWndState = WinGetState($aWindows[$i][1]) $count += 1 ToolTip("count = " & $count, 0, 0, "state = " & $iWndState) Next Sleep(1000) WEnd Link to comment Share on other sites More sharing options...
Xandy Posted January 17, 2019 Share Posted January 17, 2019 (edited) Not sure what you want differently from what you have. Is this a language barrier? Nice name. Edited January 17, 2019 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
itauto3 Posted January 17, 2019 Author Share Posted January 17, 2019 I want to count: 1, 2, 3, 4, 5... Link to comment Share on other sites More sharing options...
itauto3 Posted January 17, 2019 Author Share Posted January 17, 2019 (edited) This works: $count += (1/$aWindows[0][0]) Edited January 17, 2019 by itauto3 Link to comment Share on other sites More sharing options...
itauto3 Posted January 17, 2019 Author Share Posted January 17, 2019 What if I want to reset count, whenever new window (Notepad) opens? Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2019 Share Posted January 17, 2019 Technically you're only ever seeing the last item in the array and you're counting how many times you loop not the number of Windows example if you use the following you'll see the state for each window. For $i = 1 To $aWindows[0][0] $iWndState = WinGetState($aWindows[$i][1]) $count += 1 ToolTip("count = " & $count, 0, 0, "state = " & $iWndState) Sleep(1000) Next Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2019 Share Posted January 17, 2019 You can check to see if a new notepad window using something like the following: #include <Array.au3> Global $aWindows, $iWndState, $iWinCount = 0 While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iWinCount = $aWindows[0][0] For $i = 1 To $aWindows[0][0] $iWndState = WinGetState($aWindows[$i][1]) ToolTip("count = " & $i, 0, 0, "state = " & $iWndState) Sleep(1000) Next EndIf Sleep(1000) WEnd Link to comment Share on other sites More sharing options...
itauto3 Posted January 17, 2019 Author Share Posted January 17, 2019 1 hour ago, Subz said: You can check to see if a new notepad window using something like the following: #include <Array.au3> Global $aWindows, $iWndState, $iWinCount = 0 While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iWinCount = $aWindows[0][0] For $i = 1 To $aWindows[0][0] $iWndState = WinGetState($aWindows[$i][1]) ToolTip("count = " & $i, 0, 0, "state = " & $iWndState) Sleep(1000) Next EndIf Sleep(1000) WEnd With this code, count is always 1. Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2019 Share Posted January 17, 2019 (edited) It works fine for me although it would always keep the last Tooltip if all Notepad windows are closed since $i starts at 1 not 0. You would just need to add an "if" statement as follows. If no windows are found it will return count = 0 and state = -, if you open multiple notepad instances it will display the last window state in the loop. Global $aWindows, $iWndState, $iWinCount = 999 While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iWinCount = $aWindows[0][0] If $iWinCount = 0 Then ContinueLoop ToolTip("count = 0", 0, 0, "state = -") For $i = 1 To $aWindows[0][0] $iWndState = WinGetState($aWindows[$i][1]) ToolTip("count = " & $i, 0, 0, "state = " & $iWndState) Sleep(1000) Next EndIf Sleep(1000) WEnd Edited January 17, 2019 by Subz Link to comment Share on other sites More sharing options...
itauto3 Posted January 17, 2019 Author Share Posted January 17, 2019 (edited) With your code "count" is always 1 if one window, if two it count just 1, 2, if three it counts just 1, 2, 3. Edited January 17, 2019 by itauto3 Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2019 Share Posted January 17, 2019 Are you using the code as posted? How many notepad instances are opened? What do you expect the count to be? Link to comment Share on other sites More sharing options...
itauto3 Posted January 17, 2019 Author Share Posted January 17, 2019 I want the count to normally count, like a clock, 1, 2, 3... But, when new Notepad window opens, it should start from 0 and again count like a clock, to n. Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2019 Share Posted January 17, 2019 Whats the point of the For/Next loop as the $iWndState will always be for the last window in the loop? I think this is what you're after. Global $aWindows, $iWndState, $iWinCount = 999, $iCount While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iCount = 0 $iWinCount = $aWindows[0][0] Switch $iWinCount Case 0 $iWndState = "-" Case Else $iWndState = WinGetState($aWindows[$aWindows[0][0]][1]) EndSwitch EndIf Sleep(1000) ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState) $iCount += 1 WEnd Link to comment Share on other sites More sharing options...
TheSaint Posted January 17, 2019 Share Posted January 17, 2019 (edited) $count = 0 $result = 0 . . . . $result = $result & ", " & $count += 1 Is that maybe what you are after? That should give you - 0, 1, 2, 3, etc. If you don't want 0, just trim it or adjust the code with an ElseIf. Edited January 17, 2019 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
itauto3 Posted January 18, 2019 Author Share Posted January 18, 2019 21 hours ago, Subz said: Whats the point of the For/Next loop as the $iWndState will always be for the last window in the loop? I think this is what you're after. Global $aWindows, $iWndState, $iWinCount = 999, $iCount While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iCount = 0 $iWinCount = $aWindows[0][0] Switch $iWinCount Case 0 $iWndState = "-" Case Else $iWndState = WinGetState($aWindows[$aWindows[0][0]][1]) EndSwitch EndIf Sleep(1000) ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState) $iCount += 1 WEnd The state of the window is always 15? Link to comment Share on other sites More sharing options...
Subz Posted January 18, 2019 Share Posted January 18, 2019 You seem to want to be spoon fed the answer, it would only take a couple of changes to that code to get what you want, hint make the if statement one line to equal $iCount and remove the EndIf. Link to comment Share on other sites More sharing options...
itauto3 Posted January 18, 2019 Author Share Posted January 18, 2019 On 17. 1. 2019 at 12:45 PM, Subz said: Whats the point of the For/Next loop as the $iWndState will always be for the last window in the loop? I think this is what you're after. Global $aWindows, $iWndState, $iWinCount = 999, $iCount While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iCount = 0 $iWinCount = $aWindows[0][0] Switch $iWinCount Case 0 $iWndState = "-" Case Else $iWndState = WinGetState($aWindows[$aWindows[0][0]][1]) EndSwitch EndIf Sleep(1000) ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState) $iCount += 1 WEnd Do I have to replace existing if statement or add a new one? Link to comment Share on other sites More sharing options...
Subz Posted January 18, 2019 Share Posted January 18, 2019 (edited) Global $aWindows, $iWndState, $iWinCount = 999, $iCount While 1 $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]")) If $iWinCount <> $aWindows[0][0] Then $iCount = 0 $iWinCount = $aWindows[0][0] Switch $iWinCount Case 0 $iWndState = "-" Case Else $iWndState = WinGetState($aWindows[$aWindows[0][0]][1]) EndSwitch ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState) Sleep(1000) $iCount += 1 WEnd Edited January 18, 2019 by Subz Link to comment Share on other sites More sharing options...
itauto3 Posted January 22, 2019 Author Share Posted January 22, 2019 Not working, just for one window opened. Link to comment Share on other sites More sharing options...
itauto3 Posted February 5, 2019 Author Share Posted February 5, 2019 Can someone help me with this? Window state should be changing - the best would be, if it would track the state of active window (that is currently in front of others - among all Notepad windows). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now