而 GetKeyState 无故发送 ESC

while GetKeyState sends ESC for no reason

我做了一个函数,松开按钮 (f4) 后,该函数发送 ESC 2 次 我通过在用 } 关闭函数后写 Send {esc} 来反驳它 虽然我仍然可以看到它发生并且它触发了我。 有修复吗?

~^f4::
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 950)
Sleep, 100
Send {x}
Sleep, 100
while GetKeyState("f4")
{
Sleep, 100
Send {r}
Sleep, 100
Send {enter}
Sleep, 30
Send {esc}
Sleep, 100
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", -950)
Sleep, 100
Send {e}
Sleep, 100
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 50
Send {enter}
Sleep, 10
Send {esc}
Sleep, 100
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 950)
}
Send {esc}
return

根据我的理解解决:

~^f4::
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 950)
Sleep, 100
Send {x}
Sleep, 100
while GetKeyState("f4")
{
Sleep, 100
Send {r}
Sleep, 100
Send {enter}
Sleep, 30
if !GetKeyState("f4")
    break
Send {esc}
Sleep, 100
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", -950)
Sleep, 100
Send {e}
Sleep, 100
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 5
Send {Left}
Sleep, 50
Send {enter}
Sleep, 10
if !GetKeyState("f4")
    break
Send {esc}
Sleep, 100
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 950)
}
Send {esc}
return