I have a short question about a IF with WinActive.
I use a simple script like that:
I don't post the complete script because it would be to long.SetTimer,IsActive,300
return ;Halts script on first run to prevent misfire.
; CTRL + ALT + (num) 0
IsActive:
if(WinActive(StarCraft II ahk_class StarCraft II))
{
if(SentKey0 = "") ;Verify key wasn't already fired.
Send ^!{Numpad0} ;Send hotkey if it wasn't already fired.
return
} else {
if(SentKey1 = "")
Send ^!{Numpad1}
return
}
Basically it press a hotkey when SC2 is focused, and when I leave SC2 it sends another hotkey.
I have variables for it.
SentKey0 := ""
SentKey1 := ""
And after the hotkey got pressed it will be:
SentKey0 := !""
so that the button will not be pressed every 300ms.
Now to my questions:
This is working:
Code: Select all
if(WinActive("Untitled - Notepad"))
Code: Select all
if(WinActive(StarCraft II ahk_class StarCraft II))
It's working with:
Code: Select all
if(WinActive("StarCraft II"))
So theoretically I should be able to use it that way:
Code: Select all
if(WinActive(StarCraft II ahk_class StarCraft II) || WinActive(World of Warcraft ahk_class GxWindowClass))
I put an AFK check around my WinActive check:
Code: Select all
; CTRL + ALT + (num) 0
IsActive:
if(AFK = "") {
if(WinActive(StarCraft II ahk_class StarCraft II) || WinActive(World of Warcraft ahk_class GxWindowClass))
{
if(SentKey0 = "") ;Verify key wasn't already fired.
Send ^!{Numpad0} ;Send hotkey if it wasn't already fired.
return
} else {
if(SentKey1 = "")
Send ^!{Numpad1}
return
}
}
Code: Select all
if(AFK = !"") {
AFK := ""
} else {
AFK := !""
}
Now I have a question to that:
- Do I need a IsActive: for all new blocks?
At the moment I only have the "CTRL + ALT + NumPad 0" hotkey pressed when the game (any game in the list, the list will be pretty long...) is Active.
But when I want a check for others things?! Like when the browser or just notepad is Active and I want the hotkey "CTRL + ALT + NumPad 2" get pressed for example.
Do I need it that way:
Code: Select all
; CTRL + ALT + (num) 0
IsActive:
if(AFK = "") {
if(WinActive(StarCraft II ahk_class StarCraft II) || WinActive(World of Warcraft ahk_class GxWindowClass))
{
if(SentKey0 = "") ;Verify key wasn't already fired.
Send ^!{Numpad0} ;Send hotkey if it wasn't already fired.
return
} else {
if(SentKey1 = "")
Send ^!{Numpad1}
return
}
}
; CTRL + ALT + (num) 2
IsActive:
if(AFK = "") {
if(WinActive(Untitled - Notepad))
{
if(SentKey2 = "") ;Verify key wasn't already fired.
Send ^!{Numpad2} ;Send hotkey if it wasn't already fired.
return
} else {
if(SentKey1 = "")
Send ^!{Numpad1}
return
}
}
I'm not 100% sure how the syntax of AHK works. But I guess the
IsActive:
means that the next IF is connected to this IsActive.
So that I need a 2nd IsActive for the notepad check.
This post in short:
1. Question:
How can I ask WinActive detailed, like the Window Title + ahk_class within the IF. I know there's a #IfWinActive thing.
But when I would use this, I would need an ELSE block seperated. Like #IfNotWinActive and then I have to list the whole games again...
So this would be reduntant. And since I like (and know) the normal if statements this works for me. Just need to know how to ask for title + ahk_class.
2. Question:
Do I need an extra IsActive: for every new "block" I create?
You saw my code examples. I have a IsActive: with IF for the games. If the game is Active it press CTRL + ALT + Num0.
When not it press: CTRL + ALT + Num1
Now when I would want to check for something else, so that CTRL + ALT + Num2 get pressed do I need a 2nd IsActive: BLOCK?
I have to put all the numblock numbers as automatically pressed hotkeys. 0 is main. 1 is default if a window is NOT in the list.
2 could be browser. 3 could be skype and so on That's why I need more "blocks" for it.
Thanks for reading all of this.
I know I made this post much longer as maybe needed. Since it's only about 2 simple short questions.
EDIT:
I have another small question.
Why is this not working:
Code: Select all
Send {ctrl down}{alt down}{Numpad9}{alt up}{ctrl up}
CTRL + 1
it send the code above. So basically it would to CTRL + ALT + Num9
What I try is, I set 1 hotkey, which will press 3 different hotkeys after another.
Something like that:
Code: Select all
#o::
Send {ctrl down}2{ctrl up}
sleep 10
Send {ctrl down}{alt down}{Numpad9}{alt up}{ctrl up}
sleep 10
Send {ctrl down}1{ctrl up}
return
I would add a little delay (sleep) in it. So that the switch from PC1 to PC2 have time, before the "CTRL + ALT + Num9" hotkey get pressed.
But this:
Code: Select all
Send {ctrl down}{alt down}{Numpad9}{alt up}{ctrl up}
{Numpad9}
part, since I tried ctrl down and ctrl up already, and it was working in another script.
Okay, I tested a lot now. This:
Code: Select all
#o::
Send {ctrl down}{alt down}{Numpad3}{ctrl up}{alt up}
return
Buuut the program itself does not get this pressed hotkey?!?!?!? Q__Q
I'm talking about OBS (http://www.obsproject.com).
I want to switch a scene with a hotkey being pressed from AHK.
When I press the hotkey manually on my keyboard:
CTRL + ALT + Numpad3
it's working. It switch the scene. But when AHK is doing it, it wont work.
Anyone any idea?!
I tried:
Code: Select all
#o::
controlSend,, ^!{Numpad3},ahk_class Qt5QWindowIcon
return
EDIT 2:
What the hell, this is working:
Code: Select all
^!6::
{
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
return
}
When I use simple things like CTRL + 2 it's NOT working O.o ........
This is just, more than strange... But in the automatic script it's only working like 70% of the time.
Sometimes it's not switching the scene. Maybe I have to put a WAIT in it or something :-\ ......... I'm totally frustrated about this scene switching not working with autohotkey.
Somehow Autohotkey use a strange hotkey send method :\
THIS btw seems working all the time:
Code: Select all
#o::
{
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
return
}