
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 摸着石头过河 很多不懂
1 nexklee OP 哭了 这排版都是啥呀 哪里还有什么第 9 行 /捂脸 |
2 nexklee OP |
3 FYFX Jan 18, 2024 > 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 的行只会执行一次 |
4 FYFX Jan 18, 2024 你把 v_Enable 放到外面初始化也是行的 你这个 if(v_Enable := !v_Enable){...} 写法也挺魔法的。。。 |
6 nexklee OP @FYFX #4 v_Enable := False XButton2:: ; { v_Enable := !v_Enable If (v_Enable := False) { SetTimer Label1, 0 ; } Else { SetTimer Label1, 600 ; } return } 这是我最早的 但 V2 版报错 |
7 FYFX Jan 18, 2024 那里面可能要加一下 global v_Enable 声明,看你报错怎么说的 |
8 nexklee 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) { ... 这种最奇葩的样子 成功 |