Why a Sub is Only Executed Once?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stargeneral
Posts: 8
Joined: 11 Nov 2015, 20:15

Why a Sub is Only Executed Once?

15 Nov 2015, 15:17

I build a script that checks whether the active window has changed if it is, some actions are performed.
My question is, why foldedcardscheck is activated only once?
Specifically, if the new window is activated, the subroutine is triggered, but if the active window doesn't change, the gosub isn't triggered anymore. Why? I don't get it

Code: Select all

loop {
    sathwnd := WinExist("StackAndTile ahk_class AutoHotkeyGUI")
    winwaitnotactive, % "ahk_id " winExist("A")
    mousegetpos,,,id
    
    WinGetClass, windowClass, ahk_id %id%
    if (windowClass = "PokerStarsTableFrameClass" OR  windowClass = "Antares Game Client Window Class")
        {   
            if (lastID)
            {
            IPC_Send(sathwnd, "ignoretable=" . Lastid)   
            WinGetTitle, prevIgnoredTitle, ahk_id %lastId% 
            winmove, ahk_id %lastID%,, x,y,w,h
            }

            wingetpos, x,y,w,h, ahk_id %id%
            IPC_Send(sathwnd, "ignoretable=" . id)
            WinGetTitle, actIgnoredTitle, ahk_id %Id% 
            winmove, ahk_id %id%,, 421, 156, 1016, 727
            WinActivate, ahk_id %id%
            gosub, foldedcardscheck
            if (windowClass = "PokerStarsTableFrameClass" OR  windowClass = "Antares Game Client Window Class")
            lastID := id
         }   
    ToolTip, %prevIgnoredTitle% actual: %actIgnoredTitle%   
}
Return


foldedcardscheck:
     WinGetClass, zoomedClass, ahk_id %id%
     ;MsgBox, %zoomedClass%
     ;MsgBox, %zoomedTitle% %zoomedClass%, Debug
     WinGetPos, zoomedX, zoomedY,,, ahk_id %id%
     ;msgbox, %zoomedX% , %zoomedY% , %zoomedClass%
     If (zoomedX = 421 AND zoomedY = 156 AND zoomedClass = "PokerStarsTableFrameClass")
      {
      PixelGetColor, foldedCards, 473, 485
      ;tooltip, %foldedcards%
      msgbox, %foldedcards%
      /*
        if (foldedCards = "0x1B1B1B")   ; allora ho foldato
            {
            mousegetpos,,,zoomedId
            IPC_Send(sathwnd, "stacktable=" . zoomedId)
            IPC_Send(sathwnd, "ignoretable=" . zoomedId)
            }
            */  
      }
Return
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Why a Sub is Only Executed Once?

15 Nov 2015, 15:49

not fully following the script
but "active window has changed if it is" is actually
when the window under the mouse is of class "PokerStarsTableFrameClass" OR "Antares Game Client Window Class"
one more thing: shouldn't you change "Antares Game Client Window Class" to the actual Antares Game Client Window Class
stargeneral
Posts: 8
Joined: 11 Nov 2015, 20:15

Re: Why a Sub is Only Executed Once?

15 Nov 2015, 16:01

Me neither :p actually a friend of mine build it and I tweak it a little bit.
Essentially the script checks whether there's some difference between the current active window and the previous one, if it is the new active window will be move and the previous will be restore in its original position.

but "active window has changed if it is" is actually
when the window under the mouse is of class "PokerStarsTableFrameClass" OR "Antares Game Client Window Class"


I believe the same thing, in fact I don't understand the script completely that's why I asked


one more thing: shouldn't you change "Antares Game Client Window Class" to the actual Antares Game Client Window Class

No, because "Antares Game Client Window Class" is the real class name
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Why a Sub is Only Executed Once?

15 Nov 2015, 16:43

sorry for being redundant: can you check for that class name?
even though it's uncommon yet I believe it's possible.
OK, simply put: the code won't execute if the window under the mouse's class isn't what's specified, NOT when the active window change.
is that what you want?
this is just to collect some info:
so, make some MsgBox along the way and see where it stops, what line does it stop at.
and make a tooltip, just before winwaitnotactive to show you the active window
stargeneral
Posts: 8
Joined: 11 Nov 2015, 20:15

Re: Why a Sub is Only Executed Once?

15 Nov 2015, 17:43

You are not redundant, ty a lot for your help...
Anyway I can guarantee you that window classes are correct, but for some reason, the gosub is only triggered once, and I checked it using msgbox, if the window with the selected class is active, the gosub is triggered once, and I have no clue why...
Maybe it's worth noticing that I'm using another software that activate the window under the mouse


anyway

Image
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Why a Sub is Only Executed Once?

16 Nov 2015, 17:28

first let me apologize for a second time about that class thing.
can you see the log using this script and may be you can tell what's going on

Code: Select all

Gui, +Resize
Gui, Add, Button,  gCopyList, Copy List
Gui, Add, ListView, xm y+5 w500 h500 hWndhList, N°|Title|Info
Gui, Show, AutoSize NoActivate, What's goining on!
LV_ModifyCol(1,30)
LV_ModifyCol(2,100)

loop {
	LV_Add("", LV_GetCount()+1, "Loop", "index: " A_Index)
    sathwnd := WinExist("StackAndTile ahk_class AutoHotkeyGUI")
	winExist("A") ; set the active window as LastFound
	WinGetTitle, t
	WinGetClass, c
    LV_Add("", LV_GetCount()+1, "Waiting for", "title: " t " >> class: " c)
	winwaitnotactive
	LV_Add("", LV_GetCount()+1, "Deactivated", "last window deactivated ")
    mousegetpos,,,id
 
    WinGetClass, windowClass, ahk_id %id%
	LV_Add("", LV_GetCount()+1, "Window under the mouse", "Class: " windowClass)
	
    if (windowClass = "PokerStarsTableFrameClass" OR  windowClass = "Antares Game Client Window Class")
        {   
			LV_Add("", LV_GetCount()+1, "class condition", "the condition for the window under the mouse's met")
            if (lastID)
            {
				LV_Add("", LV_GetCount()+1, "IPC_Send", "to be executed")
            IPC_Send(sathwnd, "ignoretable=" . Lastid)   
            WinGetTitle, prevIgnoredTitle, ahk_id %lastId% 
            winmove, ahk_id %lastID%,, x,y,w,h
            }else{
			
			LV_Add("", LV_GetCount()+1, "IPC_Send", "not to be executed")
			}
 
            wingetpos, x,y,w,h, ahk_id %id%
            IPC_Send(sathwnd, "ignoretable=" . id)
            WinGetTitle, actIgnoredTitle, ahk_id %Id% 
            winmove, ahk_id %id%,, 421, 156, 1016, 727
            WinActivate, ahk_id %id%
            gosub, foldedcardscheck
            if (windowClass = "PokerStarsTableFrameClass" OR  windowClass = "Antares Game Client Window Class")
				lastID := id
         }else{
			LV_Add("", LV_GetCount()+1, "class condition", "the condition for the window under the mouse's NOT met")
		 }  
    ToolTip, %prevIgnoredTitle% actual: %actIgnoredTitle%   
LV_ModifyCol(, "autohdr")
}
Return
 
 
foldedcardscheck:
     WinGetClass, zoomedClass, ahk_id %id%
     ;MsgBox, %zoomedClass%
     ;MsgBox, %zoomedTitle% %zoomedClass%, Debug
     WinGetPos, zoomedX, zoomedY,,, ahk_id %id%
     ;msgbox, %zoomedX% , %zoomedY% , %zoomedClass%
     If (zoomedX = 421 AND zoomedY = 156 AND zoomedClass = "PokerStarsTableFrameClass")
      {
      PixelGetColor, foldedCards, 473, 485
      ;tooltip, %foldedcards%
	  LV_Add("", LV_GetCount()+1, "label", "the label foldedcardscheck is called")
      ;msgbox, %foldedcards%
      /*
        if (foldedCards = "0x1B1B1B")   ; allora ho foldato
            {
            mousegetpos,,,zoomedId
            IPC_Send(sathwnd, "stacktable=" . zoomedId)
            IPC_Send(sathwnd, "ignoretable=" . zoomedId)
            }
            */  
      }
Return
CopyList:
ControlGet, ListContent, List, , , ahk_id %hList% 
Clipboard := ListContent
MsgBox, Copied
return
esc::
ExitApp
hope this goes smoothly, this way you way know where the script blocks or conditions aren't met, things like this, you can add an item to the listview at any place that you suspect is the problem

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Hugh Jars, Mateusz53, MrDoge, peter_ahk and 379 guests