【问题标题】:How can you make the output of a key dependent on the duration which it is pressed. (in ahk, Autohotkey)如何使按键的输出取决于按键的持续时间。 (在 ahk,自动热键)
【发布时间】:2021-12-14 20:46:11
【问题描述】:

基本上,我想要的是 F9 键在按下 500 毫秒以下时转换为 Ctrl + W 并在任何时间超过 500 毫秒时转换为 Esc。 谢谢

【问题讨论】:

    标签: autohotkey


    【解决方案1】:
    $F9::
    Keywait, F9, T0.5 ; waits 0.5 seconds maximally for F9 to be released
    if ErrorLevel     ; pressed for above that time
         Send ^w
    else
         Send {Esc}
    Return
    

    $F9::
    Keywait, F9, T0.5 ; waits 0.5 seconds maximally for F9 to be released
    if ErrorLevel     ; pressed for above that time
    {
         KeyWait, F9  ; wait for F9 to be released
         Send ^w    
    }
    else
         Send {Esc}
    Return
    

    https://www.autohotkey.com/docs/commands/KeyWait.htm

    【讨论】:

    • 由于某种原因,它总是立即发送 Esc 而不是 ^w,我不知道为什么 :( 我也尝试过 Errorlevel=0 或 =1 并且我还在 if (expression) {statement} 周围加上了括号,但是无济于事。
    • 在独立脚本中尝试编辑答案中的第二个代码(仅使用脚本中的上述代码并关闭所有其他可能干扰的脚本)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多