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 

Suspend the script when some applications are active

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Da Rossa



Joined: 06 Dec 2007
Posts: 361

PostPosted: Mon Feb 08, 2010 7:23 am    Post subject: Suspend the script when some applications are active Reply with quote

Hi, I'd like to have my script suspended when the active window is one of the programs I have on a list.

So far, I managed to suspend the script only in one application, which is FileZilla, adding the following to the beginning of the code.

Code:
Loop,
{
WinWaitActive, ahk_class wxWindowClassNR
   {
   Suspend, on
   Sleep, 5
   WinWaitNotActive, ahk_class wxWindowClassNR
      {
      Suspend, off
      }
   }

}
return


This is because my hostrings mess with the directories navigation. Other applications that require the hotstrings to be suspended are the command prompts, so as the file managers like Windows Explorer and its alternatives.

The downside is that this block cannot be repeated. If I copy-paste this block replacing the ahk_class for the other program, only the first will cause the script to suspend.

How to circumvent this?

Thanks!
_________________
AHK is perfect.
Back to top
View user's profile Send private message
None



Joined: 28 Nov 2009
Posts: 3086

PostPosted: Mon Feb 08, 2010 7:37 am    Post subject: Reply with quote

I would use a SetTimer
Code:
SetTimer CheckWindow, 100

CheckWindow:
IfWinActive ahk_class wxWindowClassNR
  {
  Suspend , On
  Return
  }
IfWinActive ahk_class ConsoleWindowClass ;Comand prompt in XP
  {
  Suspend , On
  Return
  }
Suspend , Off
Return

a::MsgBox This is a Hotkey to Test
You can put as many in this as you want Cool
Back to top
View user's profile Send private message
Da Rossa



Joined: 06 Dec 2007
Posts: 361

PostPosted: Mon Feb 08, 2010 11:34 pm    Post subject: Reply with quote

Oh my God man, that seem to work, thanks! Never heard of the SetTimer command also... But won't this routine executed every 100 miliseconds hog a little my resources (my pc is kinda old), enough to have the hotstrings to feel that undesired delay? Or am I paranoid?

Thanks anyway!
_________________
AHK is perfect.
Back to top
View user's profile Send private message
None



Joined: 28 Nov 2009
Posts: 3086

PostPosted: Mon Feb 08, 2010 11:42 pm    Post subject: Reply with quote

If it causes a noticible lag make the timer longer. Very Happy
Edit: I just checked with Task Manager on My 1 Gig machine it uses less than 1 persent as is. But even if you make it 1000 chances are you are still moving the mouse around or getting your hands in position when the next pass comes around.
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Tue Feb 09, 2010 12:01 am    Post subject: Reply with quote

@Da Rossa
You might have a look at this command
it allows you to specify windows by a criteria and add that criteria to a group, then the group can be used in place of a single window reference.

http://www.autohotkey.com/docs/commands/GroupAdd.htm

OTOH, it sure seems like you are "doing it the hard way"

Why not have "Context-sensitive Hotkeys" ?
http://www.autohotkey.com/docs/Hotkeys.htm#Context
Back to top
View user's profile Send private message
Da Rossa



Joined: 06 Dec 2007
Posts: 361

PostPosted: Tue Feb 09, 2010 12:11 am    Post subject: Reply with quote

Hmm, just like I suspected...
My code endep up like this:
Code:
SetTimer CheckWindow, 100

CheckWindow:
IfWinActive ahk_class wxWindowClassNR
  {
  Suspend , On
  Return
  }
IfWinActive ahk_class ConsoleWindowClass ;Comand prompt in XP
  {
  Suspend , On
  Return
  }
Suspend , Off
IfWinActive ahk_class ATL:ExplorerFrame
  {
  Suspend , On
  Return
  }
Suspend , Off

Return


And, when ahk_class ATL:ExplorerFrame is active, the icon keeps blinking at the system tray. The same for ahk_class ExploreWClass. So this is lag.
Curiously, when ahk_class wxWindowClassNR is active, it doesn't blink. Why?

Edit: @Leef: looking at your idea now. I was writing my post when you posted yours.
_________________
AHK is perfect.
Back to top
View user's profile Send private message
Da Rossa



Joined: 06 Dec 2007
Posts: 361

PostPosted: Tue Feb 09, 2010 12:43 am    Post subject: Reply with quote

Ok, here we go.

I implemented the following, which appers to be working very fine:

Code:
GroupAdd, ExcluirDasHotstrings, ahk_class ATL:ExplorerFrame
GroupAdd, ExcluirDasHotstrings, ahk_class ExploreWClass
GroupAdd, ExcluirDasHotstrings, ahk_class ConsoleWindowClass
GroupAdd, ExcluirDasHotstrings, ahk_class wxWindowClassNR

[...]

#IfWinNotActive, ahk_group ExcluirDasHotstrings,



"Excluir das hotstrings" means exclude from hotstrings scope.

This is indeed the easier way.
Thanks!!
_________________
AHK is perfect.
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Tue Feb 09, 2010 1:24 am    Post subject: Reply with quote

Quote:
This is indeed the easier way.
I only recently found out about the GroupAdd command. Glad it worked for you.

Best Wishes.
Back to top
View user's profile Send private message
Da Rossa



Joined: 06 Dec 2007
Posts: 361

PostPosted: Tue Feb 09, 2010 1:25 am    Post subject: Reply with quote

Thanks!
And thanks to None too!
_________________
AHK is perfect.
Back to top
View user's profile Send private message
Display posts from previous:   
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