[auto hot key]不同触发方式示例
单键双击触发
; 双击Ctrl,切换窗口
~LCtrl::
KeyWait Ctrl
if (A_PriorHotkey=A_ThisHotkey && A_TimeSincePriorHotkey < 400 && A_TimeSincePriorHotkey > 100)
[执行内容]
return
单键的三种触发方式
实现方式1 一键剪切复制粘贴
[Key]::
KeyWait,[Key],T0.4
if not(ErrorLevel){
; 双击剪切
if (A_PriorHotkey=A_ThisHotkey && A_TimeSincePriorHotkey < 400 && A_TimeSincePriorHotkey > 100)
Send, ^{x}
; 单击复制
Else
Send, ^{c}
}else{
; 长按粘贴
Send, ^{v}
KeyWait,[Key]
}
return
实现方式2
正常的单双三击按键,应该由一个立即触发的单击和不会被单击影响的双击三击组成。以下为Autohotkey文档官方用例,延迟了单击的响应换取互不影响的单双三击功能。
; 示例 #3: 检测热键的单次, 两次和三次按下。
; 允许热键根据您按下次数的多少执行不同的操作。
[Key]::
KeyWait,[Key],T0.4
if not(ErrorLevel) {
if winc_presses > 0 ; SetTimer 已经启动, 所以我们记录键击.
{
winc_presses += 1
return
}
; 否则, 这是新开始系列中的首次按下. 把次数设为 1 并启动计时器
winc_presses = 1
SetTimer, KeyWinC, -400 ; 在 400 毫秒内等待更多的键击.
} else {
Send, [Key]
KeyWait, [Key]
}
return
KeyWinC:
if winc_presses = 1 ; 此键按下了一次.
{
[Action1]
}
else if winc_presses = 2 ; 此键按下了两次.
{
[Action2]
}
else if winc_presses > 2
{
MsgBox, Three or more clicks detected.
}
; 不论触发了上面的哪个动作, 都对 count 进行重置为下一个系列的按下做准备:
winc_presses = 0
return
实现方式3
实现方式2记录一个400ms的区间内的键击数,然后实现对应的功能。实现方式3略作修改,将记录一个400ms的区间内的键击数修改为每键击一次刷新400ms的输入窗口,减轻一点硬性输入要求。
global Counter := 0
[热键]::
SetTimer, Func_, -400
Counter := Counter + 1
Return
Func_:
switch Counter
{
case 1:
Msgbox,,,1,1
case 2:
Msgbox,,,2,1
case 3:
Msgbox,,,3,1
case 4:
Msgbox,,,4,1
case 5:
Msgbox,,,5,1
}
Counter := 0
Return

浙公网安备 33010602011771号