首页 > 解决方案 > 如何使按键的输出取决于按键的持续时间。(在 ahk,自动热键)

问题描述

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

标签: autohotkey

解决方案


$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


推荐阅读