【问题标题】:Autohotkey 3 clicks = volume mute自动热键 3 次点击 = 静音
【发布时间】:2018-09-30 01:46:56
【问题描述】:

在自动热键中,我试图做到这一点,以便当我按鼠标左键 3 次延迟 +/- 10 毫秒时,它会变成静音

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

【问题讨论】:

    标签: autohotkey


    【解决方案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
    

    【讨论】:

      【解决方案2】:

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

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

      使用自动热键命令 (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 系统上对其进行了测试,并且可以正常工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-16
        • 1970-01-01
        • 2021-01-31
        相关资源
        最近更新 更多