I seem to have a problem turning off my CapsLock key after starting a script.
I am using CapsLock + r to call 2 methods on a timer, as a toggle: that means
1st press (Caps + r) => start timer for calling those 2 methods regularly
2nd press (Caps + r) => stop timer for calling those 2 methods.
What happens is half okay: my script is started and stopped, but the problem is that when stopping the methods (2nd combo press), caps lock is not turned off, like in the 1st press.
As a test, i have also added a new shortcut to close things, with RButton, and that works.
Do you have any idea what i'm doing wrong?
Thanks in advance for any help.
Here is the script(also attached):
Code: Select all
#NoEnv
#SingleInstance, force
#MaxHotkeysPerInterval 500
#WinActivateForce
global ahk_sublime := "ahk_exe sublime_text.exe"
; for temp.ahk
global allToggles := {}
#If WinActive(ahk_sublime)
;-------------------------------------------------
; tf2: press reload and autoclick
CapsLock & R::
; SetStoreCapsLockMode, Off
; SetCapsLockState AlwaysOff
CallMethodWithTimer("pressR", 500)
SetCapsLockState Off
Return
~RButton::
; SetStoreCapsLockMode, Off
; SetCapsLockState AlwaysOff
if ( WinActive(ahk_sublime) && IsToggleOn("pressR")) {
CallMethodWithTimer("pressR", 1)
}
SetCapsLockState Off
Return
#If
pressR() {
; SetCapsLockState AlwaysOff
if (WinActive(ahk_sublime)) {
SendInput {r}
}
; SetCapsLockState Off
}
;-------------------------------------------------
; setup a timer for calling a method
CallMethodWithTimer(methodName, timer) {
global allToggles
toggle := !allToggles[methodName]
allToggles[methodName] := toggle
if (toggle) {
SetTimer %methodName%, % timer
} else {
SetTimer %methodName%, Off
}
}
IsToggleOn(methodName){
global allToggles
return allToggles[methodName]
}