#ifWinActive not working with controller script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gx240
Posts: 20
Joined: 11 Jul 2017, 03:03

#ifWinActive not working with controller script

11 Jul 2017, 03:17

This script does what I want, but it works everywhere and not just in the window I specify with #ifWinActive. I've never had a problem with #ifWinActive not working before, but I also don't typically use controllers or write scripts for them. Is there some kind of issue being caused by the WatchAxis or Persistent commands? Have I missed something else?

Code: Select all

SetTitleMatchMode, 3
#ifWinActive Final Fantasy III

#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return

WatchAxis:
GetKeyState, JoyZ, JoyZ  ; Get position of Z axis.

if (JoyZ > 55 or JoyZ < 45)
	{
        Send {return down}
	sleep 10
        Send {return up}
	sleep 10
	}
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: #ifWinActive not working with controller script

11 Jul 2017, 05:57

I don't think that the "#ifwinActive" directive is doing anything in your script, because it affects only hotkeys and hotstrings; and I really don't think that a 'Getkeystate' command qualifies as that.
This is probably the reason why your script runs in general. Instead, you could probably add the corresponding function/command in your 'WatchAxis' sub (see https://autohotkey.com/docs/commands/WinActive.htm), not the directive... to check for a specific active window.

On the other hand, the 'Final Fantasy' window might ignore AHK actions for some anti-cheating or other reasons. Or, you just have to run it in windowed mode or as admin. In this question, our gaming gurus (or even the search fucntion of the forum) can probably shed more light on the isssue.
gx240
Posts: 20
Joined: 11 Jul 2017, 03:03

Re: #ifWinActive not working with controller script

11 Jul 2017, 06:54

gregster wrote: On the other hand, the 'Final Fantasy' window might ignore AHK actions for some anti-cheating or other reasons. Or, you just have to run it in windowed mode or as admin. In this question, our gaming gurus (or even the search fucntion of the forum) can probably shed more light on the isssue.
Oh, the macro works fine in the game window; in fact it works everywhere. I'm trying to stop it from working anywhere except the game window. That's why I'm trying to add the #ifwinActive line, to prevent it from working anywhere else. There isn't any anti-cheating software built into this program. (It's an old single-player only title.)
gregster wrote:I don't think that the "#ifwinActive" directive is doing anything in your script, because it affects only hotkeys and hotstrings; and I really don't think that a 'Getkeystate' command qualifies as that.
Well, that explains why it isn't doing anything. I didn't realize #ifwinActive only affected certain commands. I thought it applied to everything that comes after it.

I did try the link you provided, but it doesn't cover the WatchAxis command. Like I said I'm not really familiar with these special controller specific functions, and I can't even find the WatchAxis command listed in the manual. When I search Google the only references I can find to WatchAxis are a couple example scripts, but none of them ever actually explain the command itself and what options or arguments it uses. Is there more information on WatchAxis available anywhere?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: #ifWinActive not working with controller script

11 Jul 2017, 07:19

'WatchAxis' is not a command, just a random label name for a subroutine (see https://autohotkey.com/docs/misc/Labels.htm). You could also call it 'WashMyCar' instead, but if you look closely, you see that SetTimer (https://autohotkey.com/docs/commands/SetTimer.htm) calls it every 5 milliseconds - it will probably be a little bit slower in practice.

So, naturally, the link I provided doesn't mention this specific label name. I just wanted to hint at the difference of directive "#ifWinActive" vs. the command "IfWinActive" (https://autohotkey.com/docs/commands/WinActive.htm). So... if you add the WinActive command, including the window name, to the subroutine called 'WatchAxis' (including { } brackets around the commands that should be executed if 'true'; the same as with the if command there) , it would be also executed every 5ms and would make your script kind of "window-sensitive".

Btw, your subroutine called 'WatchAxis' also misses a 'return' at the end - which probably doesn't hurt in the specific case of this short snippet, but if you would have additional code, like other subroutines, after that code block, then it would matter. Then script execution just would 'fall through' to the next 'return'...

I would recommend to take also a look at the Tutorial (https://autohotkey.com/docs/Tutorial.htm) to get a hang of the basic concepts of AHK, although (Set)Timer(s) and Labels are not really covered there. For these, look at the links above.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, Rohwedder, ruespe and 380 guests