 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Brandon7s
Joined: 06 Oct 2008 Posts: 8
|
Posted: Mon Oct 06, 2008 5:43 am Post subject: Hotkeys only when media player is active |
|
|
I'm making a script that changes the the s, a, q, and w keys to the arrow keys, when I hold down capslock. I want these keys to change only when I have the jetAudio (media player) application as the active window.
This is what I have so far. I'm a noob at this, as you might be able to see
| Code: |
IfWinActive, ahk_class Afx:400000:8:0:0:7eb02db
{
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
return
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
return
}
IfWinActive, jetAudio
{
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
return
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
return
}
IfWinActive, ahk_class COWON Jet-Audio MainWnd Class
{
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
return
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
return
}
|
There's got to be a way to simplify this. Repeating the body of the code three times, one for each wintitle seems sloppy. Is there a better way to do this?
Is there a way to make the IfWinActive code work like this?
| Code: |
IfWinActive, (ahk_class COWON Jet-Audio MainWnd Class) OR (jetAudio) OR (ahk_class Afx:400000:8:0:0:7eb02db)
|
If so, could someone show me how?
[Title edited. Please write descriptive titles for your topics. ~jaco0646] |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Mon Oct 06, 2008 5:44 am Post subject: |
|
|
| Code: | | IfWinActive, (ahk_class COWON Jet-Audio MainWnd Class) OR (jetAudio) OR (ahk_class Afx:400000:8:0:0:7eb02db) |
should be:
| Code: | | If (WinActive("ahk_class COWON Jet-Audio MainWnd Class") OR WinActive("jetAudio") OR WinActive("ahk_class Afx:400000:8:0:0:7eb02db")) |
|
|
| Back to top |
|
 |
Brandon7s
Joined: 06 Oct 2008 Posts: 8
|
Posted: Mon Oct 06, 2008 6:02 am Post subject: |
|
|
Thank you Krogdor! I can't test this out until I get home in the morning, but I will test it as soon as I am able.
I appreciate the help and the speedy reply.  |
|
| Back to top |
|
 |
Brandon7s
Joined: 06 Oct 2008 Posts: 8
|
Posted: Mon Oct 06, 2008 12:13 pm Post subject: |
|
|
| Code: | | If (WinActive("ahk_class COWON Jet-Audio MainWnd Class") OR WinActive("jetAudio") OR WinActive("ahk_class Afx:400000:8:0:0:7eb02db")) |
I tried this out, but the hotkeys were available to every window and application, as opposed to just the ones that are specified in the command.
Anyone know why?
Also, I found that IfWinActive doesn't work correctly in my original script, I have to use #IfWinActive. |
|
| Back to top |
|
 |
vahju
Joined: 17 Feb 2008 Posts: 296
|
Posted: Mon Oct 06, 2008 11:26 pm Post subject: |
|
|
Here is a example from the help file.
| Code: |
if WinActive("ahk_class Notepad") or WinActive("ahk_class" . ClassName) ; "ahk_class" need not have a space after it.
WinClose ; Uses the last found window.
|
|
|
| Back to top |
|
 |
pokercurious
Joined: 16 Dec 2007 Posts: 48
|
Posted: Tue Oct 07, 2008 1:39 am Post subject: |
|
|
from the manual:
| Quote: | | The #IfWin directives are positional: they affect all hotkeys and hotstrings physically beneath them in the script. They are also mutually exclusive; that is, only the most recent one will be in effect. |
so even if you had been using #IfWinActive in your first example, only the last one would have worked, and the hotkeys wouldn't have worked in the first 2 windows.
You can test if any of the 3 applications are active using krogdor's code within the hotkey definitions (untested, but should work assuming the winactive() parameters are correct):
| Code: | ; jetaudioactive() tests to see if any of your 3 programs is currently active
; - returns true if any is, false if none are
jetaudioactive() {
return WinActive("ahk_class COWON Jet-Audio MainWnd Class") OR WinActive("jetAudio") OR WinActive("ahk_class Afx:400000:8:0:0:7eb02db")
}
!Capslock::
if jetaudioactive()
SetCapsLockState, Off
return
^Capslock::
if jetaudioactive()
SetCapsLockState, On
return
Capslock::
if jetaudioactive()
return
Capslock & s::
if jetaudioactive()
Send,{Up}
return
Capslock & a::
if jetaudioactive()
Send,{Down}
return
Capslock & q::
if jetaudioactive()
Send, {Left}
return
Capslock & w::
if jetaudioactive()
Send, {Right}
return |
|
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Tue Oct 07, 2008 8:43 am Post subject: |
|
|
or you can use ahk_groups
| Code: | GroupAdd, MyGroup, ahk_class COWON Jet-Audio MainWnd Class
GroupAdd, MyGroup, jetAudio
GroupAdd, MyGroup, ahk_class Afx:400000:8:0:0:7eb02db
#IfWinActive, ahk_group MyGroup
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
#IfWinActive, |
untested _________________ Ternary (a ? b : c) guide TSV Table Manipulation Library
Post code inside [code][/code] tags! |
|
| Back to top |
|
 |
Brandon7s
Joined: 06 Oct 2008 Posts: 8
|
Posted: Thu Oct 09, 2008 3:23 pm Post subject: |
|
|
| [VxE] wrote: | or you can use ahk_groups
| Code: | GroupAdd, MyGroup, ahk_class COWON Jet-Audio MainWnd Class
GroupAdd, MyGroup, jetAudio
GroupAdd, MyGroup, ahk_class Afx:400000:8:0:0:7eb02db
#IfWinActive, ahk_group MyGroup
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
#IfWinActive, |
untested |
Aha, this worked quite well, and is simple enough for my feeble non-programmer mind to comprehend. - Thanks guys for all the assistance. |
|
| Back to top |
|
 |
JD Guest
|
Posted: Thu Oct 09, 2008 9:13 pm Post subject: |
|
|
If it were me, I would have done it like so, it's the easiest way for my mind to comprehend it. Amazing how all our minds work so differently.
| Code: | IfWinActive, ahk_class Afx:400000:8:0:0:7eb02db
DoIt()
IfWinActive, jetAudio
DoIt()
IfWinActive, ahk_class COWON Jet-Audio MainWnd Class
DoIt()
DoIt()
{
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
return
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
} |
|
|
| Back to top |
|
 |
Brandon7s
Joined: 06 Oct 2008 Posts: 8
|
Posted: Tue Oct 14, 2008 9:12 am Post subject: |
|
|
| JD wrote: | If it were me, I would have done it like so, it's the easiest way for my mind to comprehend it. Amazing how all our minds work so differently.
| Code: | IfWinActive, ahk_class Afx:400000:8:0:0:7eb02db
DoIt()
IfWinActive, jetAudio
DoIt()
IfWinActive, ahk_class COWON Jet-Audio MainWnd Class
DoIt()
DoIt()
{
!Capslock::SetCapsLockState, Off
^Capslock::SetCapsLockState, On
return
Capslock::return
Capslock & s::Send,{Up}
Capslock & a::Send,{Down}
Capslock & q::Send, {Left}
Capslock & w::Send, {Right}
} |
|
Niice. This could be really useful for me. Not necessarily in this project, but in another one somewhat similar. Thanks for the tip. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Tue Oct 14, 2008 10:18 am Post subject: |
|
|
| Brandon7s wrote: | | Niice. This could be really useful for me. |
I wouldn't think it would be useful for anyone, since hotkeys can't be put into functions like that... that script doesn't even compile, nor can it be translated into an easy-to-read hotkey (de)activation function. It is essentially equivalent to "DWIM(x)". _________________ Ternary (a ? b : c) guide TSV Table Manipulation Library
Post code inside [code][/code] tags! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|