Autohotkey 脚本 - hotstring 阻止 if 语句工作
Autohotkey script - hotstring prevents if statement from working
:*:pl::pleaseHelpMe ; hotstring
:*:rf::reallyConfused ; hotstring
toggle := 0
\::
if (toggle = 0)
{
Run "https://www.google.com.sg/"
}
return
上面的代码不适用于击键“\”
但是,下面的代码在没有热字串的情况下也能工作
toggle := 0
\::
if (toggle = 0)
{
Run "https://www.google.com.sg/"
}
return
为什么会这样?我该如何绕过它并使用我的热字串和击键“\”来打开 google。谢谢十亿!!
您不能在热键或热字串之间定义变量。
必须定义一个变量
- 在脚本的自动执行部分(脚本顶部,
在第一个 return 或热键之前),
- 或在热键中,
- 或函数中。
示例:
; top of the script:
toggle := 0
return ; end of auto-execute section
; toggling a variable:
F1:: toggle := !toggle ; Pressing F1 changes the value of the variable "toggle" between 1 (true) and 0 (false)
:*:pl::pleaseHelpMe ; hotstring
:*:rf::reallyConfused ; hotstring
\::
if (toggle) ; If the value of the variable "toggle" is 1 (true)
Run "https://www.google.com.sg/"
else
Send, \
return
user3419297 错误。 AutoHotkey 不需要在使用前定义变量。如果未定义变量,则在计算期间会自动为其赋予 False 或 0 值。
此代码有效,我只向热键添加了 $ 选项以防止热键自行触发:
; toggling a variable:
F1:: toggle := !toggle ; Pressing F1 changes the value of the variable "toggle" between 1 (true) and 0 (false)
:*:pl::pleaseHelpMe ; hotstring
:*:rf::reallyConfused ; hotstring
$\::
if (toggle) ; If the value of the variable "toggle" is 1 (true)
Run "https://www.google.com.sg/"
else
Send, \
return
esc::exitApp
:*:pl::pleaseHelpMe ; hotstring
:*:rf::reallyConfused ; hotstring
toggle := 0
\::
if (toggle = 0)
{
Run "https://www.google.com.sg/"
}
return
上面的代码不适用于击键“\”
但是,下面的代码在没有热字串的情况下也能工作
toggle := 0
\::
if (toggle = 0)
{
Run "https://www.google.com.sg/"
}
return
为什么会这样?我该如何绕过它并使用我的热字串和击键“\”来打开 google。谢谢十亿!!
您不能在热键或热字串之间定义变量。
必须定义一个变量
- 在脚本的自动执行部分(脚本顶部, 在第一个 return 或热键之前),
- 或在热键中,
- 或函数中。
示例:
; top of the script:
toggle := 0
return ; end of auto-execute section
; toggling a variable:
F1:: toggle := !toggle ; Pressing F1 changes the value of the variable "toggle" between 1 (true) and 0 (false)
:*:pl::pleaseHelpMe ; hotstring
:*:rf::reallyConfused ; hotstring
\::
if (toggle) ; If the value of the variable "toggle" is 1 (true)
Run "https://www.google.com.sg/"
else
Send, \
return
user3419297 错误。 AutoHotkey 不需要在使用前定义变量。如果未定义变量,则在计算期间会自动为其赋予 False 或 0 值。
此代码有效,我只向热键添加了 $ 选项以防止热键自行触发:
; toggling a variable:
F1:: toggle := !toggle ; Pressing F1 changes the value of the variable "toggle" between 1 (true) and 0 (false)
:*:pl::pleaseHelpMe ; hotstring
:*:rf::reallyConfused ; hotstring
$\::
if (toggle) ; If the value of the variable "toggle" is 1 (true)
Run "https://www.google.com.sg/"
else
Send, \
return
esc::exitApp