Stopping my script when I tab out of my game? Topic is solved

Ask gaming related questions
hcr
Posts: 3
Joined: 09 Jul 2016, 07:22

Stopping my script when I tab out of my game?

09 Jul 2016, 07:49

I have a script I use to automate certain repititve actions in "The Elder Scrolls IV: Oblivion" (I use similiar scripts in other games).

To ensure the hotkeys only trigger while I have the window open I use "#IfWinActive ahk_class Oblivion ;Limits Hotkeys in this block to running on Oblivion" up the top of the script.

But if I forget to stop them before I change windows, they keep going, sometimes preventing me from getting back to oblivion to stop them (they all feature a boolean toggle variable, but because the hotkeys only work whilst in Oblivion, I can't toggle them from outside).

Recently (ok, the last few hours) I've tried to build a check for the active window into the subroutine that I use as the basis of my loops with IfWInActive, IfWinNotActive, & WinGetClass, attempting to call whichever I'm using at the start of each iteration, so they can toggle the booleans (all of them) to false, theoretically then stopping execution of the rest of the script.

As test hotkey that used WinGetClass to get the class of the window & pop a msgbox worked fine by itself, but as soon as I move it down to my subroutine, all my hotkeys stop working...

I didn't keep samples of the various attempts I made, but the most recent unsuccessful subroutine contained (unfortunately my stored code is from a later iteration where I tried using ControlSend & ControlClick to supercede the need for a termination condition, so this is a partial reconstruction):

Code: Select all

;Practice Acrobatics
AppsKey & $SC133::
{
  bAcrobatics := !bAcrobatics
  if (bAcrobatics) {
      SetTimer, Loops, 1
     }
  else {
      SetTimer, Loops, Off
  }
}
return

Loops:
{
  SetKeyDelay, 50, 75
  WinGetClass, UID
  if (UID = "Oblivion") {
    if (bAcrobatics) {
        Send, {w down}{space}{w up}
    }
    else {
       GoSub, DeactivateAll
	}
  }
  else {
    GoSub, DeactivateAll
  }
}
I did try a variation of Leef_Me's script in the 5th post of https://autohotkey.com/board/topic/6551 ... ngtesting/ but putting an IfWinNotActive block above the #IfWinActive for the rest of the script only seemed to trigger if the win wasn't active when I launched/loaded the script (i.e. always on load, but never again).
User avatar
Capn Odin
Posts: 1308
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Stopping my script when I tab out of my game?  Topic is solved

09 Jul 2016, 11:43

Try changing

Code: Select all

WinGetClass, UID
to

Code: Select all

WinGetClass, UID, A
This will use the active window instead of the last found one.
Please excuse my spelling I am dyslexic.
hcr
Posts: 3
Joined: 09 Jul 2016, 07:22

Re: Stopping my script when I tab out of my game?

09 Jul 2016, 18:39

Brilliant, that did it! Thank you.

Unfortunately I don't see how to make the solved notation, though a post from may suggests changing the topic so that's what I'll do.
User avatar
Capn Odin
Posts: 1308
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Stopping my script when I tab out of my game?

09 Jul 2016, 18:50

hcr wrote:Brilliant, that did it! Thank you.

Unfortunately I don't see how to make the solved notation, though a post from may suggests changing the topic so that's what I'll do.
I believe there is a small graphic next to the topic title, try clicking it.
Please excuse my spelling I am dyslexic.
hcr
Posts: 3
Joined: 09 Jul 2016, 07:22

Re: Stopping my script when I tab out of my game?

09 Jul 2016, 18:59

Capn Odin wrote:I believe there is a small graphic next to the topic title, try clicking it.
Not in the browsers I have installed on any of my devices (which don't include Internet Exploder 'cos I dislike how 3rd party apps launch it all the time), but my edit of the first posts topic went to moderation (which might also be a reason I can't see a "solved" button), so they may do it for me.

Return to “Gaming”

Who is online

Users browsing this forum: GridVin and 15 guests