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 

Want a hotkey only Active on certain Window

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



Joined: 24 Apr 2009
Posts: 87

PostPosted: Fri Feb 12, 2010 8:57 pm    Post subject: Want a hotkey only Active on certain Window Reply with quote

Hi Guys,
I did some search on the Forum, but the results did not worked for me.
So i need to ask you for advice:

The problem that i have is, that the Traytip is only shown
when TargetWin is active, but the defined hotkeys still
work outside the active Window.

I do not get that fixed.
Any Ideas?

Thank You!


Code:


TargetWin = WinTitle

SetTimer, Label_Active_Window_Hotkey, 1000

Label_Active_Window_Hotkey:
WinGetTitle, Active_Title, A

IfEqual, Active_Title, %TargetWin%
   {
   TrayTip,CurrentTitle, %TargetWin% , ,
   
   ;Reload GUI
   Hotkey,^R, Re_Load

   ;Compress Text
   Hotkey,^ENTER, TextCompress

   ;GoForIt
   Hotkey, ^+ENTER, GoForIt
   }
Else
   {
   TrayTip
   Msgbox, Test
   }


Re_Load:
Return

TextCompress:
Return

GoForIt:
Return


Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Fri Feb 12, 2010 9:01 pm    Post subject: Reply with quote

Have you tried using
Code:
Hotkey, IfWinActive/Exist [, WinTitle, WinText]

You can also turn off the Hotkey
Code:
Hotkey,^R, Re_Load,Off

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
None



Joined: 28 Nov 2009
Posts: 3086

PostPosted: Fri Feb 12, 2010 9:02 pm    Post subject: Reply with quote

Or #IfWinActive
Back to top
View user's profile Send private message
Deep-Silence



Joined: 24 Apr 2009
Posts: 87

PostPosted: Fri Feb 12, 2010 9:51 pm    Post subject: Reply with quote

Thanks, but this code does not work, for some strange reason.

HotKeyIt wrote:
Have you tried using
Code:
Hotkey, IfWinActive/Exist [, WinTitle, WinText]

You can also turn off the Hotkey
Code:
Hotkey,^R, Re_Load,Off



I have put together that code, which does not work, too.

Code:


TargetWin = Test
Gui, Show, h309 w500, %TargetWin%

SetTimer, Hotkey_Label, 1000

Hotkey_Label:
IfWinActive, %TargetWin%,
   {
   Hotkey,^R, Re_Load
   Hotkey,^ENTER, TextCompress
   Hotkey, ^+ENTER, Goforit
   TrayTip,CurrentTitle, %TargetWin% , ,
   }
Else
   {
   Hotkey,^R, Re_Load,Off
   Hotkey,^ENTER, TextCompress,Off
   Hotkey, ^+ENTER, Goforit,Off
   TrayTip
   }
   
Return
   
Re_Load:
Msgbox, Reload_it
Return

TextCompress:
Msgbox, Text_Compress
Return

Goforit:
Msgbox, Goforit
Return

Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Fri Feb 12, 2010 10:46 pm    Post subject: Reply with quote

Try that:
Code:
TargetWin = Test
Gui, Show, h309 w500, %TargetWin%

SetTimer, Hotkey_Label, 1000

Hotkey_Label:
   IfWinActive, %TargetWin%,
      TrayTip,CurrentTitle, %TargetWin% , ,
   Else
      TrayTip
   Hotkey,IfWinActive,%TargetWin%
   Hotkey,^R, Re_Load
   Hotkey,^ENTER, TextCompress
   Hotkey, ^+ENTER, Goforit
   Hotkey,IfWinActive
Return
   
Re_Load:
Msgbox, Reload_it
Return

TextCompress:
Msgbox, Text_Compress
Return

Goforit:
Msgbox, Goforit
Return


Does title have to be dynamic Question
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Deep-Silence



Joined: 24 Apr 2009
Posts: 87

PostPosted: Fri Feb 12, 2010 11:08 pm    Post subject: Reply with quote

Thanks, Your Code works.
Really Great!

Now i need to step through it.
And Yes, the title is gonna be dynamic.
This Hotkey Section is only a part of a larger Script.
From time to time i renew the Title definition to keep it
up2date.

Is there no need to put the code following the "Else" into brackets?
e.g.

Code:

{
TrayTip
Hotkey,IfWinActive,%TargetWin%
Hotkey,^R, Re_Load
Hotkey,^ENTER, TextCompress
Hotkey, ^+ENTER, Goforit
Hotkey,IfWinActive
}


Thank you again
HotKeyIt


HotKeyIt wrote:
Try that:
Code:
TargetWin = Test
Gui, Show, h309 w500, %TargetWin%

SetTimer, Hotkey_Label, 1000

Hotkey_Label:
   IfWinActive, %TargetWin%,
      TrayTip,CurrentTitle, %TargetWin% , ,
   Else
      TrayTip
   Hotkey,IfWinActive,%TargetWin%
   Hotkey,^R, Re_Load
   Hotkey,^ENTER, TextCompress
   Hotkey, ^+ENTER, Goforit
   Hotkey,IfWinActive
Return
   
Re_Load:
Msgbox, Reload_it
Return

TextCompress:
Msgbox, Text_Compress
Return

Goforit:
Msgbox, Goforit
Return


Does title have to be dynamic Question
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Fri Feb 12, 2010 11:24 pm    Post subject: Reply with quote

Deep-Silence wrote:
Is there no need to put the code following the "Else" into brackets?


This is the if part for Hotkeys Exclamation
Code:
Hotkey,IfWinActive,%TargetWin%
Hotkey,IfWinActive

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Deep-Silence



Joined: 24 Apr 2009
Posts: 87

PostPosted: Fri Feb 12, 2010 11:34 pm    Post subject: Reply with quote

As i part of my larger script if have cut your code
down to my needs:

I try to follow it logically, without success.
if you wouldn't mind, could you please explain
your code with the help of comments?

Thank You...

Code:

SetTimer, Hotkey_Label, 1000

Hotkey_Label:
IfWinActive, %TargetWin%,
   {
   ;TrayTip,CurrentTitle, %TargetWin% , ,
   }
Else
   {
   ;TrayTip
   Hotkey,IfWinActive,%TargetWin%
   Hotkey,^R, Re_Load
   Hotkey,^ENTER, TextCompress
   Hotkey, ^+ENTER, Goforit
   Hotkey,IfWinActive
   }

Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Sat Feb 13, 2010 10:09 am    Post subject: Reply with quote

Read about Hotkey,IfWinActive in help. Each time you run it, your hotkeys will change.
Code:
SetTimer, Hotkey_Label, 1000

Hotkey_Label:
   Hotkey,IfWinActive,%TargetWin% ;Hotkeys below that line will be only active for given window
   Hotkey,^R, Re_Load
   Hotkey,^ENTER, TextCompress
   Hotkey, ^+ENTER, Goforit
   Hotkey,IfWinActive ;reset Hotkey command back to normal
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
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