Sign in to follow this  
Followers 0
Uten

Problem with WinActive and regexp

16 posts in this topic

#1 ·  Posted (edited)

EDIT: Problem solved itself? I really don't know why. That bothers me a bit but life goes on ;)

EDIT2: Turns out something fishy is going on after all.

I have some code witch I would like to be able to detect if a certain window is active by using regular expresions.

In this sample I use notepad and calc. Should be available on all systems.

If my regexp only contains a few chars (2) it does not work at all. If it contains more (4) it works like it should :whistle:

Could someone verify if this is correct (and a BUG) or a feature or just a mistake in my code?

Func testWinRegExp()
Opt("WinTitleMatchMode",4)
Run("calc.exe")
Run("notepad.exe")
   ;Norwegian titles
   ;Local $regexp = "regexp=.*ulat.*|.*tisblo.*"
   ;Local $regexp = "regexp=.*alku.*|.*tisblo.*"
   ;Local $regexp = "regexp=.*isblo.*|.*al.*"
   ;English titles
   ;Local $regexp = "regexp=.*calc.*|.*otepa.*" ;This works
   Local $regexp = "regexp=.*tep.*|.*al.*"        ; [b]This does not![/b] At least the Norwegian version does not.
    While WinWaitNotActive(WinGetTitle(""))
        If WinActive($regexp) Then
            ConsoleWrite("+++WinGetTitle: " & WinGetTitle("active") & @LF)
        Else
            ConsoleWrite("---WinGetTitle: " & WinGetTitle("active") & @LF)
        EndIf 
    WEnd 
EndFunc
Edited by Uten

Share this post


Link to post
Share on other sites



Hi thanks,

Witch version are you using?

This is my result :whistle:

Local $regexp = "regexp=.*isb.*|.*al.*"

>Running:(3.2.1.11):C:\portableapps\scite\..\autoit-v3.2.1.11\autoit3.exe "C:\tools\headmouse\headmouseWrap.au3"    
---WinGetTitle: C:\tools\headmouse\headmouseWrap.au3 - Sc1
---WinGetTitle: Kalkulator
---WinGetTitle: AutoIt Forujava script:emoticon(':(', 'smid_6')
:(ms -> Replying in Problem with WinActive and regexp - Mozilla Firefox
---WinGetTitle: uten navn - Notisblokk
---WinGetTitle: C:\tools\headmouse\headmouseWrap.au3 - Sc1
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 17.103

Share this post


Link to post
Share on other sites

Used the one you had un-commented

Local $regexp = "regexp=.*tep.*|.*al.*"        ; This does not! At least the Norwegian version does not.

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "H:\Autoit_files\test.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams

+> Starting AutoIt3Wrapper v.1.7.3

>Running AU3Check (1.54.4.0) params: from:C:\Program Files\AutoIt3\beta

+>AU3Check ended.rc:0

>Running:(3.2.1.11):C:\Program Files\AutoIt3\beta\autoit3.exe "H:\Autoit_files\test.au3"

---WinGetTitle: H:\Autoit_files\test.au3 - SciTE

+++WinGetTitle: Calculator

+++WinGetTitle: Untitled - Notepad

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 8.619


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

hmm, ok does not look promising.

I will have to investigate a bit further.

Anyone running a German, Dutch or any other XP version with a non windows "native" setup whom could do the same test?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

EDIT: Got to late last night :whistle: I will do a new test down belove after @jpm's post.

NOTE: You will find a slightly reworked but complete test code at the bottom of this post

I have just installed everything on a "fresh" computer and with the total installation it does not work.

Local $regexp = "regexp=.*isblo.*|.*al.*"oÝ÷ ÙÊ{­·à.|ÓÝ®+jgâêô÷`.-ßOvIÈOvëh"ÝÖ­ªiz½=Ø­ wZ¶©¥êÞÅíøþ»§þèwñ+®ÒµÓ®·ø§ß¹óOv¶%³Ovjíô÷k^²Õ¢8­ä^Lijí÷ãö®¶­ÝØ«ß¹óOv>º ­©W«Óݺڷ}øýK¬ö«jk>ëd­j»b.¶-ÝjÚ¦«¿^÷ëdnx§7
5çôãZZ­©¬çÇë¢n|4÷cë¢
Úø¥z½=Ø­ wû­Sp¡yÉ×­Î|Ó­ºyâ|ãMöÓ^5çÀ¹óOv>º ­©W«Óݺڷ}=Ù«­¢+w{·à.|ÓÝ­¢lÓÝ»}=Ú׬µh§N+ey Z»}øZ)ÆzÔâ¶W¹òë^v¯Ú-Æå¢Iqµ8­î|4÷kh¢[4÷f®ßOvµë-Z)ÓÙ^EèÆ®Ý'"LOuÞ÷÷u¢g­N+e{.µéçjù͢جnZ$h§ëSÙ^çÀ¹óOv¶%³Ovjíô÷k^²Õ¢8­ä^LijíÒr$Ä÷]èwZ)ÆzÔâ¶W¹òë^v¯Ú-Æå¢I>ë`.¶Ýì^zw^9óN¶­r^çÍg¹ó^yïoܡסØÊ)à*Þìi¶®¶­sdÆö6Âb33c·&VvWÒgV÷C·&VvWÒâ¦6&Æòâ§Ââ¦Æ²â¢gV÷CoÝ÷ Ø  Ý×hzÌ(®G(uî¶ß¹óOv>º ­©W«Óݺڷ}=Ù'"LM=Ø­ wZ¶©¥êô÷`.¶-ÝjÚ¦«{·ãúîúk¡ßÄ®º+J×Nºßâ~çÍ=ÚÚ(Í=Ù«·ÓÝ­zËVtâ¶Wz1¥«·ßÚºÚ"·wb¯~çÍ=Øú趦~)^¯Ovëh"Ý÷ãõ,z³Ú­©¬û­µªíxºÚ·u«j^®ý{ß­ºyâÜ(^rN4×7Óij¶¦³®¹ð.|ÓÝ®+jgâêô÷`.¶-ßî¶MÂç$zw^v·9óN¶Féçx9ó7ÛMx×çÍ=Øú趦~)^¯Ovëh"Ýô÷f®¶­Ýì^ß¹óOv¶%³Ovjíô÷k^²Õ¢8­ä^Lijí÷ãï¾Z)ÆzÔâ¶W¹òë^v¯Ú-Æå¢Iqµ8­î|4÷kh¢[4÷f®ßOvµë-Z)ÓÙ^EèÆ®Ý'"LOuÞ÷÷¾ùh§ëSÙ^çË­zyÚ¾sh¶+$Z)ÆzÔâ¶W¹ð.|ÓÝ­¢lÓÝ»}=Ú׬µh§N+ey Z»t1=×zßÝþûå¢g­N+e{.µéçjù͢جnZ$h§ëSÙ^çÀ¹óOv¶%³Ovjíô÷k^²Õ¢8­ä^LijíÒr$Ä÷]èwûïqµ8­î|)©dºV­¢µ¢g­N+e{çÍ=ÚÚ(Í=Ù«·ÓÝ­zËVtâ¶Wz1¥«·IÈÝw¡ýýßî¶ëh!=ÞÅç§uçks4ëa1×(uî|Ñ8¦{5ïôýÊx ò¢w¡jø§¨(¡×±¦V§µ¨¨í+zˡ׺Ú"µÍÝÙ^]
    ][ÝÞÑTÐßI][ÝË    ][ÝÓÛ]]Ò]^] ][ÝÊBÛØ[    ÌÍÜYK    ÌÍÜYÝÚ[^

B^][ÈÝÚ[^

BÜ
    ][ÝÕÚ[]SX]Ú[ÙI][ÝË
BÌÍÜYHH[ ][ÝØØ[Ë^I][ÝÊBÌÍÜYH[   ][ÝÛÝY^I][ÝÊBÓÜÙYÚX[]ÂÓØØ[ ÌÍÜYÙ^H ][ÝÜYÙ^K[]ØË][ÝÂÓØØ[  ÌÍÜYÙ^H ][ÝÜYÙ^K[ÝKØË][ÝÂØØ[  ÌÍÜYÙ^H ][ÝÜYÙ^KØË[Ë][ÝÂÑ[ÛÚ]ÂÓØØ[   ÌÍÜYÙ^H ][ÝÜYÙ^[ËÝK][ÝÈÕÈÛÜÜÂÓØØ[    ÌÍÜYÙ^H ][ÝÜYÙ^K[][ÝÈÈÈÙÈÝ    ÌÌÎÈ]XÝHÜÙYÚX[Ú[ÛÙÈÝÚ[[ØZ]ÝXÝ][Ù]]J ][ÝÉ][ÝÊJBYÚ[]J ÌÍÜYÙ^
H[ÛÛÛÛUÜ]J ][ÝÊÊÊÕÚ[Ù]]N    ][ÝÈ  [ÈÚ[Ù]]J ][ÝØXÝ]I][ÝÊH  [ÈB[ÙBÛÛÛÛUÜ]J   ][ÝËKKUÚ[Ù]]N   ][ÝÈ  [ÈÚ[Ù]]J ][ÝØXÝ]I][ÝÊH  [ÈB[[[[Â[ÈÛ]]Ò]^]

BTØÙÜÐÛÜÙJ   ÌÍÜYJBTØÙÜÐÛÜÙJ   ÌÍÜYBQ^][[È
Edited by Uten

Share this post


Link to post
Share on other sites

@Uten,

You know now we have change the RegExp engine in the beta so can you reanalyse your problem with the beta as the old engine is removed for ever.

The new is a Perl compatible regular expression (PCRE) which is more standard. We will not support anymore the old one. :whistle:

Share this post


Link to post
Share on other sites

Yes I know @jpm, probably got to late last night so I did not catch that I was running with stable when I did the last test.

I usually only use the beta (ziped version) and don't have the stable version installed.

And now to the scary part: What kind of voodoo did you pull this morning @jpm :whistle: I'm not able to recreate my problems today. Not even when I run with the setup as I did in my first post. you can see I'm running with 3.2.1.11 there. I also tried it on my regular machine yesterday with no success and today it works like a charm?

It works running with a full installation:

>"C:\Programfiler\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\tools\au3\testWinTitleRegExp.au3" /autoit3dir "C:\Programfiler\AutoIt3\beta" /UserParams 
+> Starting AutoIt3Wrapper v.1.7.3
>Running AU3Check (1.54.4.0)  params:  from:C:\Programfiler\AutoIt3\beta
+>AU3Check ended.rc:0
>Running:(3.2.1.11):C:\Programfiler\AutoIt3\beta\autoit3.exe "C:\tools\au3\testWinTitleRegExp.au3"  
+++WinGetTitle: uten navn - Notisblokk
---WinGetTitle: C:\tools\au3\testWinTitleRegExp.au3 - SciTE [3 of 3]
+++WinGetTitle: Kalkulator
---WinGetTitle: C:\tools\au3\testWinTitleRegExp.au3 - SciTE [3 of 3]
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 15.886

Running from a unziped beta with the accompanied scite:

Yikes today it works:

>"C:\portableapps\autoit-v3.2.1.11\SciTe\..\autoit3.exe" /ErrorStdOut "C:\tools\au3\testWinTitleRegExp.au3" 
+++WinGetTitle: uten navn - Notisblokk
---WinGetTitle: C:\tools\au3\testWinTitleRegExp.au3 - SciTE4AutoIt3 [3 of 3]
+++WinGetTitle: uten navn - Notisblokk
---WinGetTitle: C:\tools\au3\testWinTitleRegExp.au3 - SciTE4AutoIt3 [3 of 3]
+++WinGetTitle: Kalkulator
---WinGetTitle: C:\tools\au3\testWinTitleRegExp.au3 - SciTE4AutoIt3 [3 of 3]
>Exit code: 0   Time: 70.975

Hmm, life is unfair. I'm not able to recreate my troubles today.

Conclusion: Always sleep on it and get a head scan frequently.

Thanks for your help and interest.

Share this post


Link to post
Share on other sites

@Uten

perhaps the vodoo is the script run OK on even day !!! (Just joking)

In fact I cannot have your script working with an english version ...

some time I get the +++ sometime --- never both. I am wondering if there is a timing problem with your script as WinGetTitle executed twice can return different values.

Share this post


Link to post
Share on other sites

OK so I guess it does not work between 0200 and 0700 :whistle:

I'll see if I can find a reproducible scenario that fails. I "have" to work with this until I get a reliable solution/algorithm as it will control a headMouse application and turn on/off self triggered mouse clicks.

Share this post


Link to post
Share on other sites

Hi @jpm,

Wonder if I have stumbled upon a clue now.

As you can see from my first post I have used WinGetTitle("") in the WinWaitNotActive( ... ) And then I use WinGetTitle("active") in the ConsoleWrite calls. As of writing this does not create any error but if I change the code so I do it the other way round I get a really unexpected result.

Global $arr[4]
testWinRegExpShort()
exit

Func LoadTestApps()
   Opt("OnExitFunc","testWinRegExpShortExit")
   HotKeySet("{ESC}", "testWinRegExpShortExit")
   $arr[0] = 3
   $arr[1] = Run("calc.exe")
   $arr[2] = Run("notepad.exe")
   $arr[3] = Run("mspaint.exe")
EndFunc 
Func testWinRegExpShort()
   Local $WTMM = Opt("WinTitleMatchMode", 4)
   Local $regexp = "regexp=.*tep.*|.*al.*"
   LoadTestApps()
   While WinWaitNotActive(WinGetTitle("active")) ;Change to active and lett the two next calls be emty can result in the wron title returned
      If WinActive($regexp) Then 
         ConsoleWrite("+++" & WinGetTitle("") & @LF)
      Else
         ConsoleWrite("---" & WinGetTitle("") & @LF)
      EndIf 
   WEnd
   Opt("WinTitleMatchMode", $WTMM)
EndFunc 
Func testWinRegExpShortExit()
   Local $i
   For $i = 1 to $arr[0]
      ProcessClose($arr[$i])
   Next 
   Exit
EndFunc

The ---Untitled - Notepad lines should be ---Untitled - Paint and ---.....Sc1

>"C:\portableapps\scite\..\autoit3tools\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "G:\codeX\autoit\au3\language\testWinFunctions.au3" /autoit3dir "C:\portableapps\scite\..\autoit-v3.2.1.11" /UserParams  
+> Starting AutoIt3Wrapper v.1.7.3
>Running AU3Check (1.54.4.0)  params:  from:C:\portableapps\scite\..\autoit-v3.2.1.11
+>AU3Check ended.rc:0
>Running:(3.2.1.11):C:\portableapps\scite\..\autoit-v3.2.1.11\autoit3.exe "G:\codeX\autoit\au3\language\testWinFunctions.au3"   
+++Untitled - Notepad
[b]---Untitled - Notepad[/b]
+++Untitled - Notepad
+++Calculator
---Calculator
+++Untitled - Notepad
[b]---Untitled - Notepad
---Untitled - Notepad
---Untitled - Notepad
---Untitled - Notepad
---Untitled - Notepad
---Untitled - Notepad
---Untitled - Notepad[/b]
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 34.042

This was done on w2k-sp4 English with Norwegian localization.

Share this post


Link to post
Share on other sites

Although I think the behavior you are experiencing is kind of stupid, when using WinTitleMatchMode 4, "" means the same thing as "last", not the same thing as "active". This is different behavior because in all other modes, "" would be equivalent to "active". It's not a bug and it is documented.

Share this post


Link to post
Share on other sites

Your right @Valik. I was under the impression (even after reading the helpfile page every time I want to use mode 4 and regexp ;) ) that "" in mode 4 would return the same as "" in mode 1.

Thanks for clarifying that. :whistle:

Share this post


Link to post
Share on other sites

Don't worry about missing that one. Even I missed that and subsequently made a bug report where Valik had to take the time to explain the difference.

Valik, I know this is not your cup of tea, (I am sure you rightly feel that both of us should have more carefullly read the manual in this respect), but shouldn't the behavior be more consistent?


Who else would I be?

Share this post


Link to post
Share on other sites

Hey, like I said, I think the behavior is stupid. I think it should be consistent. I didn't even know it myself until I read the documentation to figure out why you were having a problem. I don't know if it's possible to change at this point and there is always the argument that it's documented even if it is illogical.

Share this post


Link to post
Share on other sites

Another test with unexpected result to me.

I suppose WinActive and StringRegExp should return the same result?

#include <GUIConstants.au3>
testWinActiveRegExpAgainsStringRegExp()
exit
Func testWinActiveRegExpAgainsStringRegExp()
   Opt("WinTitleMatchMode", 4)
   Local $msg, $title, $regexp
   $regexp = ".*\.cdd.*|.*[Ff]elemarksavisa.*"
   Local $gui = GuiCreate("Adobe Acrobat - [Felemarksavisa_2010_13_81.pdf]")
   GUISetState(@SW_SHOW)
   While WinWaitNotActive(WinGetTitle("active"))
      If WinActive($regexp) Then 
         ConsoleWrite("+++" & WinGetTitle("active") & @LF)
      Else
         ConsoleWrite("---" & WinGetTitle("active") & @LF)
      EndIf 
      $title = WinGetTitle("active")
      If StringRegExp($title, $regexp, 0) Then 
         ConsoleWrite("+++" & $title & @LF)
      Else
         ConsoleWrite("---" & $title & @LF)
      EndIf   
   WEnd
EndFunc

This is my result: I get the same on a Norwegian XP and a English w2k-sp4.

>"C:\portableapps\scite\..\autoit3tools\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "G:\codeX\autoit\au3\language\testWinFunctions.au3" /autoit3dir "C:\portableapps\scite\..\autoit-v3.2.1.11" /UserParams  
+> Starting AutoIt3Wrapper v.1.7.3
>Running AU3Check (1.54.4.0)  params:  from:C:\portableapps\scite\..\autoit-v3.2.1.11
+>AU3Check ended.rc:0
>Running:(3.2.1.11):C:\portableapps\scite\..\autoit-v3.2.1.11\autoit3.exe "G:\codeX\autoit\au3\language\testWinFunctions.au3"   
---G:\codeX\autoit\au3\language\testWinFunctions.au3 - Sc1 [6 of 6]
---G:\codeX\autoit\au3\language\testWinFunctions.au3 - Sc1 [6 of 6]
---Adobe Acrobat - [Felemarksavisa_2010_13_81.pdf]
+++Adobe Acrobat - [Felemarksavisa_2010_13_81.pdf]
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 14.944

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