Win active not working Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Raiden96
Posts: 38
Joined: 23 Oct 2021, 07:03

Win active not working

Post by Raiden96 » 28 Jul 2022, 10:49

Hello,

I have this code.

Code: Select all

#IfWinActive ahk_exe nioh.exe

#If A_IsSuspended
F2::
    Suspend
    soundbeep, 700, 300
return
#If
F2::
    soundbeep, 300, 500
    Suspend
return

$XButton1::
SetKeyDelay, 50, 50
Send {w down}{w up}
Send {Mbutton down}{Mbutton up}
Return

#IfWinActive
For now i want it to press both W and middle mouse at almost the same time. Say back to back.
Anyway, i want this code to execute only when im inside the game, or maybe i should say when the process is active, the window that is, is active, in focus. But for some reason the script remains in effect whether the window is in focus or not. I may be tired, but i can't seem to figure out what's wrong here. Any help would be greatly appreciated!

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Win active not working  Topic is solved

Post by mikeyww » 28 Jul 2022, 11:03

Like the #IfWin directives, #If is positional: it affects all hotkeys and hotstrings physically beneath it in the script. #If and #IfWin are also mutually exclusive; that is, only the most recent #If or #IfWin will be in effect.

Code: Select all

nioh = ahk_exe nioh.exe

F2::
Suspend, Toggle
Soundbeep, 300, 500
Return

#If WinActive(nioh) && A_IsSuspended
F2::
Suspend, Off
Soundbeep, 700, 300
Return

#If WinActive(nioh)
XButton1::
SetKeyDelay, 50, 50
Send w{MButton}
Return
#If

Raiden96
Posts: 38
Joined: 23 Oct 2021, 07:03

Re: Win active not working

Post by Raiden96 » 29 Jul 2022, 02:06

Works great. Thank you very much! Also, i didn't know you could send 2 keys like this

Code: Select all

Send w{MButton}
. It's definitely something I've never seen before. This is good to know.

PS: Still used to normal programming. Kinda odd that the 2 ifs would exclude each other. But then again, I'm a novice with ahk. There's much for me to learn about it that I don't know or understand yet.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Win active not working

Post by mikeyww » 29 Jul 2022, 05:20

I'd say that the key is remembering that #If is not If! :)

Send can have any string of characters or keys, including buttons.

Code: Select all

Send abd{Left}c{Home}

Raiden96
Posts: 38
Joined: 23 Oct 2021, 07:03

Re: Win active not working

Post by Raiden96 » 29 Jul 2022, 07:49

I see. Thanks once again! You're answers and insights have been invaluable!

Post Reply

Return to “Gaming Help (v1)”