Autohotkey - 每秒递减一次变量

时间:2012-10-02 02:23:41

标签: autohotkey

我不是AutoHotKey大师,如果变量每秒超过0,我就会遇到问题:

Loop
{
If spaceFreq > 0
    spaceFreq--
If returnFreq > 0
    returnFreq--
Sleep, 1000
}

这个脚本有什么问题?变量没有减少。

1 个答案:

答案 0 :(得分:0)

to decrement a value and store the result back in the same variable directly,
you must do
ex: Var := --x instead of Var := x--
because --x decrements X immediately and then assigns its value to Var
x-- increments X only after assigning the current value of X to Var consequently, 
not modifying the original variable, if no variable is specified.

阅读更多关于递减的here ... 我建议使用SetTimer,而不是循环和睡眠..

例如:

#Persistent
SetTimer, decrementlabel, 1000 ;1000 ms = 1 second
return

decrementlabel:
If spaceFreq > 0
   --spaceFreq
If returnFreq > 0
   --returnFreq
return