pause/stop/break script if window is not active

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

pause/stop/break script if window is not active

19 Aug 2018, 01:57

in short of it i have this little script

Code: Select all

#IfWinActive, ahk_class WarframePublicEvolutionGfxD3D11
#MaxThreadsPerHotkey 4

~MButton::
KeyDown := !KeyDown
If KeyDown
	SendInput {F11 down}
Else
	SendInput {F11 up}
Toggle1 := !Toggle1
While Toggle1{
Send, {F10}
sleep, 25
}
return
and well in game when i press mouse scroll it just atuo attack with sword
it works perfectly as on and off switch

my poblem is when its ON and for some reason i alt tab game or some window will pop up
and game stays in background i need to in best case suspend script
and un suspend it when i come back to game

if thats not possible reloading breaking or stopping script while game is not active willd be fine enough

i was trying

Code: Select all

SetTimer, CheckForWindow, 500	; this checks every 500ms = 1/2 second
IfWinNotActive, ahk_class WarframePublicEvolutionGfxD3D11
suspend
return
but that ended me up with suspending and unsuspending each 1 sec when my game was not active

so any help would be cool
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: pause/stop/break script if window is not active

19 Aug 2018, 04:00

I assume your while loop is causing you trouble, right?

If that is true, you could check if if the game is still the active window before you send the f10.

If you want the f10 still be send to the window you would have to use controlsend I assume or postmessage
ciao
toralf
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: pause/stop/break script if window is not active

19 Aug 2018, 05:31

Code: Select all

SetTimer, CheckForWindow, 500	; this checks every 500ms = 1/2 second
return

CheckForWindow:
    If WinActive("ahk_class WarframePublicEvolutionGfxD3D11")
    {
        if (A_IsPaused)
        {
            if (KeyDown)
                SendInput {F11 down}
            Pause, Off
        }
    }
    else
    {
        if (!A_IsPaused)
        {
            if (KeyDown)
                SendInput {F11 up}
            Pause, On        
        }
    }
return
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

Re: pause/stop/break script if window is not active

19 Aug 2018, 10:33

F11 is my sprint key
F10 is my attack key

Xtra your solution made only disable my sprint while game is not focused window

toralf i want to do exact thing what Xtra made but for both F10 and F11

i want to stop/pause/suspend script whenever i alt tab game or when some window will popup

would be perfect if while my autofire is on it would pause for time while game is not active window
but if alt tabbing would just reload/break or supsend script that would work for me also if making game window active again would un suspend script

in short of it any autofire or keydown activated in game should work only while game window is focused

i believe answer is easy like always but i lack the knownledge in autohotkey to do it myself
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

Re: pause/stop/break script if window is not active

19 Aug 2018, 15:44

or putting it more simple i need this piece of my script

Code: Select all

#IfWinActive, ahk_class WarframePublicEvolutionGfxD3D11
#MaxThreadsPerHotkey 4

~MButton::
KeyDown := !KeyDown
If KeyDown
	SendInput {F11 down}
Else
	SendInput {F11 up}
Toggle1 := !Toggle1
While Toggle1{
Send, {F10}
sleep, 25
}
return
to send anything anywhere as it does but only when warframe is active/focused window
when its not active/focused it would be perfect if it dont send anything at all anywhere

i think best bet for me is

Code: Select all

Lalt::reload
but that would fix my problem only if i manually alt tab game

so any other ideas are welcome
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: pause/stop/break script if window is not active

19 Aug 2018, 23:12

Did you try combining what i posted with your script? (that was the intent)
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

Re: pause/stop/break script if window is not active

20 Aug 2018, 03:01

ZeroX4 wrote:F11 is my sprint key
F10 is my attack key

Xtra your solution made only disable my sprint while game is not focused window
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: pause/stop/break script if window is not active

20 Aug 2018, 11:05

MButton will be able to trigger only if the game is focused. F11 will be held down, then released, alternating, on each MButton press, meaning if its held down and u tab out, it remains held down.
MButton will also toggle the timer on and off, on each press. if u tab out while the timer is switched on, it wont send any keystrokes but it wont be disabled either, meaning the moment the game gains focus once again, the f10 spam will resume.

Code: Select all

#If warframeActive()
~MButton::
	SendInput % "{F11 " (KeyDown := !KeyDown ? "Down": "Up") "}"
	SetTimer SendF10, % KeyDown ? "25" : "Off"
return

SendF10:
	if warframeActive()
		Send {F10}
return

warframeActive() {
	return WinActive("ahk_class WarframePublicEvolutionGfxD3D11")
}
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

Re: pause/stop/break script if window is not active

20 Aug 2018, 17:45

swagfag mbutton does not work as on off it does only as on button

while i alt tab and warframe is not focused your script in fact does stop f10 spam

but i just realised i have better idea with combining stuff from my other scripts

Code: Select all

#IfWinActive, ahk_class WarframePublicEvolutionGfxD3D11
#MaxThreadsPerHotkey 4

~MButton::

;LOOP----------------------------------------------------------------------------
Loop
{
sleep, 500
IfWinnotActive, ahk_class WarframePublicEvolutionGfxD3D11
reload
}
;LOOP----------------------------------------------------------------------------

KeyDown := !KeyDown
If KeyDown
	SendInput {F11 down}
Else
	SendInput {F11 up}
Toggle1 := !Toggle1
While Toggle1{
Send, {F10}
sleep, 25
}

return
and believe or not when i alt tab game or use windows key to make warframe lose focus it does reload my script

now problem is everything below ;LOOP---------------- section does not work (F10 spam and F11 up and down state dont work)

and if i put loop section at the bottom everything works
but then loop section dont work

so what am i missing or doing wrong?
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

Re: pause/stop/break script if window is not active

20 Aug 2018, 19:22

ok and here we have it
i was messing with stuff i found on internet about ahk and i come up with this

Code: Select all

#IfWinActive, ahk_class WarframePublicEvolutionGfxD3D11
#MaxThreadsPerHotkey 4

~MButton::
setTimer, WinCheck, 500

KeyDown := !KeyDown
If KeyDown
	SendInput {F11 down}
Else
	SendInput {F11 up}
Toggle1 := !Toggle1
While Toggle1{
Send, {F10}
sleep, 25
}

WinCheck:
IfWinnotActive, ahk_class WarframePublicEvolutionGfxD3D11
reload

Return
(turns out pistion of

Code: Select all

setTimer, WinCheck, 500
and

Code: Select all

WinCheck:
is the key factor here since SetTimer needs to be just below key and WinCheck: needs to be last function everything else needs to be between them)

works almost fine
Mbutton on off f10 spam and f11 state

when i alt tab game it reloads script

now i face new problem i didnt face before since i never use alt tab while spam is on (i believe my spam was on sometimes when i pressed mbutton in menu and then alt tab and that f10 spam made some bad stuff in other windows but now its resolved)
problem is i have under left ctrl gear menu that opens only while i hold left ctrl (this is in game function i have in my keybidings left ctrl under gear menu i did not swap it or add anything for lctrl in ahk)

and for some reason when i press mbutton and spam is on left alt turns into left ctrl wai? and how to prevent it?

i did try
#mbutton
*mbutton
$mbutton
mbutton
instead of
~mbutton

but nothing works and i also know it have something to do with SEND function since when i remove this part of script

Code: Select all

Toggle1 := !Toggle1
While Toggle1{
Send, {F10}
sleep, 25
}
alt works just fine
any ideas?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: pause/stop/break script if window is not active

20 Aug 2018, 19:32

a set of parens was missing

Code: Select all

#If warframeActive()
~*MButton::
	SendInput % "{F11 " ((KeyDown := !KeyDown) ? "Down" : "Up") "}"
	SetTimer SendF10, % KeyDown ? 25 : "Off"
return

SendF10:
	if warframeActive()
		Send {F10}
return

warframeActive() {
	return WinActive("ahk_class WarframePublicEvolutionGfxD3D11")
}
User avatar
ZeroX4
Posts: 38
Joined: 20 Aug 2016, 18:43

Re: pause/stop/break script if window is not active

20 Aug 2018, 20:49

ok im 1 step ahead

Code: Select all

#IfWinActive, ahk_class WarframePublicEvolutionGfxD3D11
#MaxThreadsPerHotkey 4

~MButton::
setTimer, WinCheck, 500

KeyDown := !KeyDown
If KeyDown
	SendInput {F11 down}
Else
	SendInput {F11 up}
Toggle1 := !Toggle1
While Toggle1{
Send, {Blind}{F10}
sleep, 25
}

WinCheck:
IfWinnotActive, ahk_class WarframePublicEvolutionGfxD3D11
reload

Return
fixes the problem that {Blind} before {F10} fixed Lalt changing into Lctrl

thx all you guys for ur help ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 245 guests