自动热键3次=静音

时间:2018-09-26 16:31:47

标签: autohotkey

在自动热键中,我试图使其延迟3次,即按 +/- 10 ms 变为音量静音

LButton::
if (?) 
{
     Send, Volume_Mute
}
else 
{
     Send, LButton
}
Return

2 个答案:

答案 0 :(得分:1)

使用A_TickCount读取当前时间(以毫秒为单位),然后计算两次点击之间的延迟。参见Date and Time

ms := A_TickCount
N := 3          ; number of clicks
T := 500        ; max delay between clicks, ms
clicks := 0

~lbutton::
    msx := A_TickCount      ; get current time
    d := msx - ms           ; get time past
    ms := msx               ; remember current time
    if (d < T) 
        clicks += 1
    else 
        clicks := 1
    if (clicks >= N) 
    {
        ; tooltip %N%-click detected 
        send {Volume_Mute}
        clicks := 0
    }
return

答案 1 :(得分:0)

您将在循环(在后台运行)中运行的每个Autohotkey脚本(example.Ahk),这些循环将以频率?... ms(毫秒)计数一次重复

如果要使用+-10ms的延迟,则需要更改计时器。 (默认= + -250ms)

使用自动快捷键命令(SetTimer),可以更改它。

(ps- + -10 ms非常快,我建议使用较低的时间频率)

在该行(SetTimer,CountClicks,100)中,您可以更改(优化)数字100。(这样它就可以在您的系统上正常工作。)

注意:您可以删除行(msgbox),这只是为了显示视觉效果您单击了多少次。

尝试此代码:

#NoEnv
#SingleInstance force
;#NoTrayIcon

a1 := -1
b1 := 0

esc::exitapp ;You can click the (esc) key to stop the script. 

;if you use ~ it will also use the default function Left-Button-Click. 
;and if you Click the Left Mouse Button 3x times, it will Execute Ahk Code Part 3
~LButton::
if(a1 = -1)
{
a1 := 4
#Persistent
SetTimer, CountClicks, 100
}
else
{
a1 := 3
}
return

CountClicks:
if(a1 = 3)
{
b1 := b1 + 1
}
if(a1 = 0)
{
msgbox you did Click <LButton> Key > %b1%x times
if (b1=1) 
{
;if Click 1x - Then Execute Ahk Code Part 1 
;Here you can put any code for Part 1       
} 
if (b1=2) 
{
;if Click 2x - Then Execute Ahk Code Part 2  
;Here you can put any code for Part 2       
} 
if (b1=3) 
{
;if Click 3x - Then Execute Ahk Code Part 3 
;Here you can put any code for Part 3  
Send {Volume_Mute} ;Send, Volume_Mute     
} 
if (b1=4) 
{
;if Click 4x - Then Execute Ahk Code Part 4 
;Here you can put any code for Part 4       
} 
b1 := 0
SetTimer, CountClicks , off
reload ; restart script
}
a1 := a1 - 1
return

我确实在Windows 10系统上对其进行了测试,并且可以正常工作。