AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug in SetTitleMatchMode?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
sinkfaze



Joined: 19 Mar 2008
Posts: 113

PostPosted: Fri Mar 21, 2008 5:50 am    Post subject: Bug in SetTitleMatchMode? Reply with quote

I had posted about this problem previously in Ask for Help, and as is often the case, the problem doesn't occur to me until after I've asked for help. Here is the sample of the testing script I posted over there, again, my intent is to have a script with a common hotkey for several sessions of a program which will have the same window title (although a common hotkey, it will eventually perform an action unique to each session). Creating a loop to rename the window titles hasn't been practical, so my aim was to get the PIDs at startup and create an ahk_group for each window:

Code:
SetTitleMatchMode, 2
Run, "C:\xxx.exe"
...     ;the omitted lines pertain to
...     ;the opening of the session
WinGet, aaa, PID, A
Sleep, 100
GroupAdd, 1, ahk_pid %aaa%
Sleep, 100
Run, "C:\xxx.exe"
...       
...       
WinGet, bbb, PID, A
Sleep, 100
GroupAdd, 2, ahk_pid %bbb%
Sleep, 100
return
Run, "C:\xxx.exe"
...
...
WinGet, ccc, PID, A
Sleep, 100
GroupAdd, 3, ahk_pid %ccc%
return

#IfWinActive ahk_group 1
^!w::
PostMessage, 0x201, 0, 0, Button, ahk_group 1
PostMessage, 0x202, 0, 0, Button, ahk_group 1
Sleep, 100
MouseClickDrag, left,  220,  165,  315,  165
Sleep, 100
SendInput ^c
Sleep, 100
Run, "C:\yyy.exe"
WinWait, yyy login,
SendInput username{ENTER}
WinWait, yyy,
PostMessage, 0x201, , , Button, yyy
PostMessage, 0x202, , , Button, yyy
Sleep, 100
SendInput no^v
return

#IfWinActive ahk_group 2
^!w::
...     ;the omitted lines are
...     ;repeated script from
...     ;the previous section
SendInput yes^v
return
#IfWinActive ahk_group 3
^!w::
...
...
...
SendInput maybe^v
return


As you can see, the end result of each hotkey's output should be different, and when I have only one session open each hotkey performs correctly i.e. only session 1 = no^, only session 2 = yes^, only session 3 = maybe^. But when I have more than one session open it falters:

Only sessions 1 & 2 open, hotkey executed/action occurs in session 1 = no^

Only sessions 1 & 3 open, hotkey executed/action occurs in session 1 = no^

Only sessions 1 & 2 open, hotkey executed/action occurs in session 2 = no^

Only sessions 1 & 3 open, hotkey executed/action occurs in session 3 = no^

Only sessions 2 & 3 open, hotkey executed/action occurs in session 2 = yes^

Only sessions 2 & 3 open, hotkey executed/action occurs in session 3 = yes^

Sessions 1, 2 & 3 open, hotkey executed/action occurs in session 1 = no^

Sessions 1, 2 & 3 open, hotkey executed/action occurs in session 2 = no^

Sessions 1, 2 & 3 open, hotkey executed/action occurs in session 3 = no^


Comparing the results to the test script it appeared that only the topmost hotkey in the order of how they were written in the script was being executed, which I verified by swapping the sections of the script around.

Once I posted my request for help I noticed the only thing that seemed out of place was SetTitleMatchMode, 2. In the abstract it doesn't belong there since I'm declaring no window titles in my script, but it was going to be in my primary script so it was necessary to add it to my test script to ensure compatability. Just as a test I remarked SetTitleMatchMode in my test script and tried it again...everything worked fine.

And on a subsequent test when I unmarked SetTitleMatchMode and specified to exclude the window title only in GroupAdd for session 1, the hotkeys would not work in any sessions in any combination iff session 1 exists. If I excluded the window title only in session 2, it would execute session 1's hotkey iff session 1 exists, but no hotkeys will execute if only sessions 2 & 3 exist, etc.

So even though I'm not specifying a window title in the #IfWinActive sections, SetTitleMatchMode was still governing the script's behavior based on the window title.

Is this a bug in the behavior of SetTitleMatchMode or am I fundamentally misunderstanding/misusing the function?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group