Bienvenido al foro amigo, en mi respuesta te presento una clase que hice para simplificar el uso de TOGGLE con funciones repetitivas o bien timers o intervalos
Puedes ver la clase que utilizo en la siguiente página (aunque lo hice en inglés)
Prueba el siguiente código, es una representación de lo que quieres hacer, espero que te funcione, si tienes algun problema no dudes en consultar.
Code: Select all
delay:=33
tog_f:=new func2timer("f_action",delay)
tog_z:=new func2timer("z_action",delay)
f_action(){
Send {LButton}
}
z_action(){
Send {RButton}
Sleep, %delay%
Send {LControl}
}
f::tog_f.toggle()
+z::tog_z.toggle()
;
; CLASS CREATED BY OSITOMALVADO
;
;
; This class simplifies the creation and use of intervals.
; You can make the function you want to repeat with a single
; line. You can also add a function that will be executed at
; the beginning and another at the end (you must add the
; initials "Start" and "Stop" to your interval function respectively)
;
;
; Constructor: receives a base function which can have
;associated "Start" and "Stop"
;
; Using:
;
; getToggleState()
; Return 1 if interval is on, else return 0
;
; toggle()
; If interval is on will be turned off, else will be turned on
;
;
; start()
; This function just start the interval, if this.function "Start" exist will be executed before the interval
;
; tick()
; This is the main function that will make the interval work, this is every step
;
; stop()
; Same as start but this is for the end
class func2timer{
state:=False
__New(fun,delay:=0){
if !IsFunc(fun)
return ErrorLevel
this.function:=fun
this.initFunction:=this.function "Start"
this.endFunction:=this.function "Stop"
this.delay:=delay
this.timer:=ObjBindMethod(this, "tick")
}
getToggleState(){
Return this.state
}
toggle(){
this.state:=!this.state
if (this.state)
this.start()
Else
this.stop()
}
start(){
if IsFunc(this.initFunction)
this.initFunction(this)
timer:=this.timer
SetTimer, % timer, % this.delay
}
tick(){
if IsFunc(this.function)
this.function(this)
}
stop(){
timer:=this.timer
SetTimer, % timer,Off
if IsFunc(this.endFunction)
this.endFunction(this)
}
}