Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v2) • Re: How to Double tap to break a looped behaviour?

$
0
0

I'm not really sure why you're experiencing those things. A completely separate timer in another script that does different things preventing an unrelated timer from working doesn't make sense, unless AHK is storing timer5000 as some global/universal name that is being shared between scripts. I don't know how to solve your problem exactly, but for fun, you can try the below script to see if it works any better for you.

CODE:

Spell1 := Spell('1', '{F5}')
Spell2 := Spell('r', '{F6}')

*1::Spell1.Cast()
*r::Spell2.Cast()


class Spell {
static cooldown := 5030 ; spell cooldown
block := false ; keep track of block
toggle := false ; keep track of timer state

__New(key_pressed, magic) {
this.key := key_pressed ; set physical key to check for
this.CastMagic := (*) => Send('{Blind}' magic) ; spell key to send
}

Cast() {
if not this.block { ; if not blocked
this.CastMagic() ; cast spell
this.block := true ; turn block on
SetTimer(() => this.block := false, -Spell.cooldown) ; turn off block after 2 seconds
}

if KeyWait(this.key, 'T0.1') and KeyWait(this.key, 'D T0.1') { ; if key is released within 100ms and pressed within 100ms
SetTimer(this.CastMagic, Spell.cooldown * (this.toggle ^= 1)) ; toggle timer that casts spell
SoundBeep() ; indicator double-tap worked
}
}
}



It's good to see another way to write it, but It freezes up like all the others. I can see this even in a basic text document: Change the output keys f5/f6 to a and b. If you presss just combinations of the inputs 1 and r....u'll see one of them freezup and stop working. I can get this consistently by: tap 1 and then tap r....and then after a brief pause holding down 1....and then holding down r....my output will no longer be combination of 'a' every5s and 'b' every 5s it'll just be 'a'....and I'm not even introducing any other keys into this process, just the two so there should be no keyboard rollover issues....i can make one of the inputs ctrl/shift and no difference either. It's really frustrating. And the code you posted even in a game and just one of the hotkeys active, will freezup when I'm pressing other keys inbetween....which is the issue with all of the setTimer code examples except for the last one I posted it bypasses the problems of that and works like the looped version for some reason.

Statistics: Posted by Kolo — 6 minutes ago



Viewing all articles
Browse latest Browse all 579

Trending Articles