如何使按键的输出取决于按键的持续时间。 (在 ahk,Autohotkey)

How can you make the output of a key dependent on the duration which it is pressed. (in ahk, Autohotkey)

基本上我想要的是F9键转换成Ctrl+W当它被按下 500 毫秒以下并进入 Esc 超过 500 毫秒的任何持续时间。 谢谢

$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