我需要在两个AutoHotkey键映射配置之间切换.我想通过F3切换两者.从我的在线研究和StackOverflow,我认为以下应该做我想要的:
#ifwinactive
next_make_mac = %1%
msgbox next_make_mac: %next_make_mac%
#If next_make_mac
msgbox Setting Mac settings.
RAlt::Control
Escape::Delete
RWin::Escape
LWin::LAlt
LAlt::LWin
next_make_mac := false
msgbox Mac settings set.
#If
#If !next_make_mac
msgbox Setting PC settings.
Ralt::Escape
msgbox PC settings set.
next_make_mac := true
#If
msgbox %next_make_mac%
F3::
Run %A_AhkPath% %A_ScriptName% %next_make_mac%
return
Run Code Online (Sandbox Code Playgroud)
但是,该#If next_make_mac指令始终评估为true.我不确定为什么会这样.事实上,即使我进入next_make_mac := false它仍然评估为真.有没有更好的方法来做我正在做的事情?
我正在运行AutoHotkey 1.1.21.03
首先,#If语句中的消息框不会按预期运行.第7行的第一个将永远消失,告诉你它Setting Mac settings.但是,您的热键将正确设置.
我认为这是由于auto-exec部分一直到达它找到的第一个热键.
只将热键放在#If语句中.
接下来,在你第一次#If声明中,你检查是否next_make_mac包含任何其他比false或0.意思是字符串"false",将评估为true.
注意,false在AHK中是相同的0.
在您的第二个#If陈述中,您正在检查是否next_make_mac包含false或0.
至于切换,因为你无法直接在#If语句中更改变量的值,所以你必须将它添加到你的F3热键中.
像这样:
F3::
next_make_mac := !next_make_mac ; Flip the value
msgBox % next_make_mac
Run %A_AhkPath% %A_ScriptName% %next_make_mac%
return
Run Code Online (Sandbox Code Playgroud)
这条线将切换next_make_mac,假设它包含两种true,false,1或0.
因此,请确保您在#If语句中只有热键,并且传递1或0作为参数而不是true或者false您不小心使用字符串,并且您的脚本应该按预期工作.
以下是更改的完整示例:
#SingleInstance, force
#ifwinactive
next_make_mac = %1%
; Check which settings we'll be using
if (next_make_mac)
msgBox, Using Mac Settings
else
msgBox, Using PC Settings
; Only hotkeys inside here
#If next_make_mac
RAlt::Control
Escape::Delete
RWin::Escape
LWin::LAlt
LAlt::LWin
#If
; Only hotkeys inside here
#If !next_make_mac
Ralt::Escape
#If
F3::
next_make_mac := !next_make_mac ; Flip the value
Run %A_AhkPath% %A_ScriptName% %next_make_mac%
return
Run Code Online (Sandbox Code Playgroud)
编辑:虽然不在问题范围内,但您也可以#SingleInstance, force在脚本顶部添加以删除该对话框,询问您是否要在每次按下时重新启动脚本F3.
| 归档时间: |
|
| 查看次数: |
121 次 |
| 最近记录: |