AutoHotKey 按键切换

AutoHotKey Key Switching

嘿,我正在尝试创建一个 ahk 脚本,它允许我按一个键 "q" 并让它切换 "e" 键以发送 "o" 或 "p" 取决于变量 "count"。我让它工作了一些,唯一的问题是我无法使用 "q" 键。当我按下 "q" 时,虽然 "e" 键确实按我想要的方式切换,但没有任何显示。

count = 1

q::
If (count = 1) {
    count = 2
    MsgBox Count is set to 2
    return
} else if (count = 2) {
    count = 1
    MsgBox Count is set to 1
    return
}

e::
If (count = 1) {
    Send o
    return
}
If (count = 2) {
    Send p
    return
}


Escape::
ExitApp
Return

要通过按键或组合键在两个不同的选项之间切换,请使用 := 运算符在 true(1) 和 false(0) 之间切换变量的值

toggle := 1 ; true (Option 1)
MsgBox Option 1: "e" to "o"

$q::     ; $ prevents the key from triggering itself
toggle := !toggle
If (toggle)
    MsgBox Option 1: "e" to "o"
else
    MsgBox Option 2: "e" to "p"
return

$e::
If (toggle)
    Send o
else
    Send p
return

要增加变量的值,请使用 ++ 运算符:

count = 0

$q::
count++
If (count = 1)
    MsgBox Count is set to 1
else 
If (count = 2)
     MsgBox Count is set to 2
else {
    count = 1 ; reset
    MsgBox Count is set to 1
}
return

$e::
If (count = 1)
    Send o
If (count = 2)
    Send p
return

https://autohotkey.com/docs/Variables.htm#Operators