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 

WinActivate : This is not a bug... but

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Surfer_ix
Guest





PostPosted: Fri Nov 10, 2006 7:30 am    Post subject: WinActivate : This is not a bug... but Reply with quote

Question
Here's what I've asked the author of AutoHotkey :

Go there, download this game :

http://www.bay12games.com/dwarves/

Launch it.

Then create an autohotkey script like aas simple as that :

Code:
#NoEnv
#SingleInstance ignore
SendMode Input

MyActiveWindow(AFenetre)
{
  WinWait, %AFenetre%
  IfWinNotActive, %AFenetre%
  {
    WinActivate, %AFenetre%
    WinWaitActive, %AFenetre%
  }
}


SetTitleMatchMode, 2 ; doit contenir AU MOINS
MyActiveWindow("Dwarf Fortress")
Exit,


; you'll notice that sometimes the window goes to front, sometimes it doesn't, and as soon as you've clicked on the "dwarf fortress" window, the autohotkey script end.

This may be a bug in WinActivate I think.

------------------------------------------
And the answer was :

Thanks for the report. Unfortunately, I don’t think there’s much that can be done to improve WinActivate because basically it amounts to only one single call to the Windows API: SetForegroundWindow(). The operating system does not provide any way to guarantee that a window will become active, so the best we can do is keep trying to activate it until it agrees to become active.

If it fails in your case, you could try a loop that continually tries to activate and/or maximize it. Also, if you have DetectHiddenWindows turned on, you could try leaving it turned off (sometimes this helps).
------------------------------------------
This fails in my case.

Question Any idea how to have this working properly ? Question
Back to top
quicktest



Joined: 30 Jul 2004
Posts: 42

PostPosted: Fri Nov 10, 2006 2:55 pm    Post subject: Reply with quote

I've run into my share of WinActivate issues, and came up with the rudimentary bandaid of using Sleep & dual activation to help alleviate it. Try the following modified code, see if it works better for you:

Code:
#NoEnv
#SingleInstance ignore
SendMode Input

MyActiveWindow(AFenetre)
{
  WinWait, %AFenetre%
  Sleep, 500
  IfWinNotActive, %AFenetre%
  {
    WinActivate, %AFenetre%
    WinActivate, %AFenetre%
    WinWaitActive, %AFenetre%
  }
}


SetTitleMatchMode, 2 ; doit contenir AU MOINS
MyActiveWindow("Dwarf Fortress")
Exit,
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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