Label1() { Send "{Numpad1}" ; Return }
XButton2::  ;
{
static v_Enable := False
If (v_Enable := !v_Enable)
{
SetTimer Label1, 0
}
Else
{
SetTimer Label1, 600
}
return
} 
代码见上,ahk V2 能正常运作,但第 9 行那个 static (静态变量)我省去就没有反应 非要加上 有什么办法不加那个静态标识吗
非程序员 三脚猫 v1 熟一点 v2 摸着石头过河 很多不懂
|  |      1nexklee OP 哭了 这排版都是啥呀 哪里还有什么第 9 行 /捂脸 | 
|  |      2nexklee OP | 
|  |      3FYFX      2024-01-18 10:26:15 +08:00 > A static variable may be initialized on the same line as its declaration by following it with := and any expression. For example: static X:=0, Y:="fox". Static declarations are evaluated the same as local declarations, except that after a static initializer (or group of combined initializers) is successfully evaluated, it is effectively removed from the flow of control and will not execute a second time. 看 ahkv2 的文档,加了 static 的行只会执行一次 | 
|  |      4FYFX      2024-01-18 10:29:22 +08:00 你把 v_Enable 放到外面初始化也是行的 你这个 if(v_Enable := !v_Enable){...} 写法也挺魔法的。。。 | 
|  |      5nexklee OP @FYFX #3  我那句是想当一个开关 按 XButton2 切换 一次非 一次是 是就按键 1 非就什么都不做 需要只执行一次吗 局部变量不行? | 
|  |      6nexklee OP @FYFX #4  v_Enable := False XButton2:: ; { v_Enable := !v_Enable If (v_Enable := False) { SetTimer Label1, 0 ; } Else { SetTimer Label1, 600 ; } return } 这是我最早的 但 V2 版报错 | 
|  |      7FYFX      2024-01-18 10:42:57 +08:00 那里面可能要加一下 global v_Enable 声明,看你报错怎么说的 | 
|  |      8nexklee OP @FYFX #7  global 可以 ,static 也可以 v_Enable := False XButton2:: ; { v_Enable := !v_Enable If (v_Enable := False) ... 没有反应 XButton2:: ; { v_Enable := False v_Enable := !v_Enable If (v_Enable := False) ... 没有反应 XButton2:: ; { static v_Enable := False If (v_Enable := !v_Enable) { ... 这种最奇葩的样子 成功 |