level 3
求脚本,比如单键按下a,输出a,长按输出1,双击输出10
2025年02月19日 11点02分
1
level 3
t1 := 0.16
t2 := 400
l::{
static lastTime := 0
if !KeyWait("l", "T" . t01)
Send "hl{Enter}"
else
Send (A_TickCount - lastTime < t02) ? "yhl{Enter}" : "l"
lastTime := A_TickCount
KeyWait("l")
}
我自己写了一个,长按,短按都没问题,但双击l实际输出为l{Enter}
2025年02月20日 13点02分
2
level 3
press() {
timeout := 300
tout := timeout / 1000
key := RegExReplace(A_ThisHotKey, "[*~$#+!^]") ; 移除修饰符
pattern := ""
Loop {
t := A_TickCount
KeyWait key ; 等待按键释放
pattern .= (A_TickCount - t > timeout) ? "1" : "0"
; 等待按键再次按下,超时返回
if !KeyWait(key, "D T" . tout)
return pattern
}
}
$l:: {
switch press() {
case "0": Send "l" ;单击
case "00": Send "yhl{Enter}" ;双击
case "1": Send "hl{Enter}" ;长按
}
}
这个可以用了,但响应时间有点长, 不太好用
2025年02月20日 16点02分
3
是的,有双击的话,单击相应时间就变长了
2025年02月21日 04点02分
level 3
最终形态
t01 := 0.2
t02 := 300
;单击长按双击,单击有延时
SLDpress(sp, lp, dp) {
static count := 0
if (!KeyWait(A_ThisHotkey, "T" . t01)) {
Send lp
KeyWait(A_ThisHotkey)
} else {
count++
SetTimer CheckDoublePress, -t02
}
CheckDoublePress() {
if(count = 1) {
Send sp
}
if(count = 2) {
Send dp
}
count := 0
}
}
g::SLDpress(A_ThisHotkey, "mg{Enter}", "gt{Enter}") ;随意调用
;单击长按, 单击无延时
SLpress(sp, lp) {
Send KeyWait(A_ThisHotkey, "T" . t01) ? sp : lp
KeyWait(A_ThisHotkey)
}
g::SLpress("11{Enter}", "30{Enter}")
2025年02月21日 08点02分
4
太牛了,这个真好用,谢谢你
2026年04月16日 10点04分
level 1
deepseek帮我改成v1版本了
t01 := 0.2 ; 长按阈值:0.2秒(200毫秒)
t02 := 300 ; 双击等待窗口:300毫秒
clickCount := 0 ; 全局变量,记录短按次数
$6::
; 第1步:等待按键弹起,最长等 t01 秒(200ms)
KeyWait, 6, T%t01%
; 第2步:判断是长按还是短按
if ErrorLevel
{
; ErrorLevel = 1 表示 KeyWait 超时
; 说明按了超过200ms还没松手 → 长按
SendInput, {U+2026}{U+2026} ; 输出省略号
KeyWait, 6 ; 等待真正松手
return
}
; ErrorLevel = 0 表示在200ms内松手了 → 短按
clickCount++ ; 短按计数+1
SetTimer, CheckDoubleClick, % -t02 ; 启动定时器,300ms后执行
Return
CheckDoubleClick:
; 300ms后执行这里
if (clickCount = 1)
SendInput, 6 ; 只有一次短按 → 输出6
if (clickCount = 2)
SendInput, :""{Left} ; 两次短按 → 输出:"
clickCount := 0 ; 重置计数
Return
2026年04月16日 10点04分
5