AutoHotkey Community

It is currently May 27th, 2012, 12:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: August 18th, 2011, 7:06 pm 
Offline
User avatar

Joined: February 17th, 2011, 6:48 pm
Posts: 427
Location: peering out from behind my favorite rock
With the following code, if "Window1" and "Window2" both exist, pressing F11 will not activate Window2, but pressing F12 will activate Window2:

Code:
ActivateAndReportLastWindowFound()
{
   WinActivate
   WinGetActiveTitle Title
   MsgBox The active window title is: %Title%
}

WinActivate Window1

#If WinExist("Window2")
   F11:: ActivateAndReportLastWindowFound()
#If
#IfWinExist Window2
   F12:: ActivateAndReportLastWindowFound()
#IfWinExist

Please help me understand why #If WinExist() does not set Last Window Found.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2011, 9:19 pm 
Offline

Joined: March 2nd, 2007, 7:25 am
Posts: 57
Location: Germany
the documentation says:
Quote:
Most behavioural properties of the #IfWin directives also apply to #If.

That means, not all apply. Setting Last Window Found seems to be one of those who don't apply.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2011, 9:58 pm 
Offline
User avatar

Joined: February 17th, 2011, 6:48 pm
Posts: 427
Location: peering out from behind my favorite rock
Thanks Barney9. It seems that the documentation left you guessing, too. :|


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2011, 10:47 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
This wasn't intentional, but a side-effect of the way quasi-threads work in AutoHotkey (and the fact that the #if expression is evaluated in its own quasi-thread). I've moved this topic to Bug Reports.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2011, 4:02 am 
Offline
User avatar

Joined: February 17th, 2011, 6:48 pm
Posts: 427
Location: peering out from behind my favorite rock
Thanks for your attention and explanation, Lexikos.

And thanks for AHK_L. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2011, 10:58 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
As a workaround, you can use #If lfw := WinExist(WinTitle). However, this won't be necessary after the next release.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2011, 3:22 pm 
Offline
User avatar

Joined: February 17th, 2011, 6:48 pm
Posts: 427
Location: peering out from behind my favorite rock
For my trivial example, your work-around works efficiently. But for a slightly more complex example, it does not (i.e. in the code below, Window1 will be reported when F12 is pressed):

Code:
ActivateAndReportLastWindowFound()
{
   WinActivate
   WinGetActiveTitle Title
   MsgBox The active window title is: %Title%
}

WinActivate Window1

AppWinExists()
{
   If ( WinExist("Window2")
     || WinExist("Window3")
     || WinExist("Window4") )
      Return True
   Else
      Return False
}

#If Ifw := AppWinExists()
   F12:: ActivateAndReportLastWindowFound()
#If

A simple but relatively inefficient work-around for this is:

Code:
#If AppWinExists()
   F12::
      AppWinExists()
      ActivateAndReportLastWindowFound()
   Return
#If

After the next release, will

Code:
#If AppWinExists()

set the last window found?

Thanks again. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2011, 2:53 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
LazyMan wrote:
But for a slightly more complex example, it does not (i.e. in the code below, Window1 will be reported when F12 is pressed):
Of course it won't work if you don't actually use the variable. What were you thinking?
Code:
#if lfw := WinExist("Window1")
F12::WinActivate ahk_id %lfw%
Quote:
#If Ifw := AppWinExists()
lfw = Last Found Window, not "I" Found Window. Well, I guess that works too...
Quote:
After the next release, will #If AppWinExists() set the last window found?
Yes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2011, 1:59 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Fixed in v1.1.02.02.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2011, 5:36 am 
Offline
User avatar

Joined: February 17th, 2011, 6:48 pm
Posts: 427
Location: peering out from behind my favorite rock
Lexikos wrote:
What were you thinking?

As I cannot reproduce the behavior which misled me to my previous post, it seems I was careless and/or particularly unlucky (probably the former). :oops: I apologize for not being more careful before posting.

In version v1.1.02.02, #If AppWinExists() behaves as I expected. Thank you! :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group