 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Piz
Joined: 16 Feb 2008 Posts: 46
|
Posted: Mon Feb 25, 2008 10:58 pm Post subject: Possible Bug with Window Match Criteria |
|
|
I apologize if this is a known bug - my searches didn't turn it up. I also apologize if it's not a bug and just me misunderstanding something.
You can just copy and run the following code: | Code: | /*
Possible bug in window title match criteria processing - the order of criteria following the window title text appears to matter.
In the example code below, the only difference between the first and third winGetTitle commands is the order of the AHK_PID and AHK_CLASS criteria. The first command successfully retrieves the window's title, the third does not.
The code below doesn't demonstrate this, but the order does still appear to matter if the criteria are added to a window group instead of being used directly. This code also does not demonstrate other criteria or ordering.
AutoHotkey version tested: 1.0.46.17
*/
msgbox 1, , This script will run Notepad, then close it after displaying three message boxes.`nClick OK to continue, Cancel to abort.
ifMsgBox CANCEL
exitApp
run c:\windows\notepad.exe
theTitle := "Untitled - Notepad"
winWaitActive %theTitle%
winGet thePid, PID, %theTitle%
winGetClass theClass, %theTitle%
;!! winGetTitle with AHK_PID before AHK_CLASS
winGetTitle title, %theTitle% AHK_PID %thePid% AHK_CLASS %theClass%
msgbox The first call to winGetTitle retrieves the window title:`n`nwinGetTitle title, %theTitle% AHK_PID %thePid% AHK_CLASS %theClass%`n`nTITLE: '%title%'`n`nPID: '%thePid%'`nCLASS: '%theClass%'`nERRORLEVEL: %ERRORLEVEL%
;!! winGetTitle with AHK_PID before AHK_CLASS, bogus class
winGetTitle title, %theTitle% AHK_PID %thePid% AHK_CLASS FOOBAR
msgbox The second call to winGetTitle shows that the class is being found and processed,`nbecause a bogus class causes the title not to be retrieved:`n`nwinGetTitle title, %theTitle% AHK_PID %thePid% AHK_CLASS FOOBAR`n`nTITLE: '%title%'`n`nPID: '%thePid%'`nCLASS: '%theClass%'`nERRORLEVEL: %ERRORLEVEL%
;!! winGetTitle with AHK_CLASS before AHK_PID
winGetTitle title, %theTitle% AHK_CLASS %theClass% AHK_PID %thePid%
msgbox The third call to winGetTitle does not retrieve the window title:`n`nwinGetTitle title, %theTitle% AHK_CLASS %theClass% AHK_PID %thePid%`n`nTITLE: '%title%'`n`nPID: '%thePid%'`nCLASS: '%theClass%'`nERRORLEVEL: %ERRORLEVEL%
winClose %theTitle%
|
Last edited by Piz on Tue Feb 26, 2008 1:37 pm; edited 1 time in total |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2364 Location: Australia, Qld
|
Posted: Tue Feb 26, 2008 4:33 am Post subject: |
|
|
Running AutoHotkey in a debugger shows that the window class criterion in the third call is "Notepad AHK_PID nnnn".
It appears a case-insensitive comparison is used to find the first/next "ahk_" tag. However, the when an ahk_class tag is encountered, a case-sensitive comparison is used to find the following "ahk_" tag. Whoops!
Changing "AHK_PID" to "ahk_PID" or "ahk_pid" solves the problem. The majority of scripts I've seen use lower-case, which is probably why this hadn't been reported before now.
To be fair, the help file does specify them in lower-case. It doesn't mention case sensitivity for ahk_ tags specifically, but it does say that window titles are case-sensitive and classes must be "exact." |
|
| Back to top |
|
 |
Piz
Joined: 16 Feb 2008 Posts: 46
|
Posted: Tue Feb 26, 2008 1:23 pm Post subject: |
|
|
Interesting. I'm in the habit of setting anything that's an AHK "keyword" (except command and built-in function names) to uppercase, to identify them as such in my code. (For example, TRUE/FALSE, ERRORLEVEL, LOCAL/GLOBAL/STATIC, etc.) I've never seen any case-sensitivity for keywords anywhere else, just in documented places like window titles and class names, as you mention. Those would be data, so the case-sensitivity there makes sense.
Probably not a big deal to fix. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10450
|
Posted: Mon Mar 03, 2008 12:49 am Post subject: |
|
|
| Thanks for spotting this. It will be fixed in the next release. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|