#Requires AutoHotkey v2.0
; Threshold for "too fast" in milliseconds
Threshold := 50
; To log debug output, set a log file path
LogFilePath := ""
*LButton::
{
; If it's too fast, ignore it
if (A_TimeSincePriorHotkey != '' and A_TimeSincePriorHotkey < Threshold)
{
flog "skipping double click"
Return
}
; Otherwise, if button is still down send the key press as normal
if (GetKeyState("LButton", "P")) {
sendinput "{Blind}{LButton down}"
}
}
*LButton up::
{
; If it's too fast, don't ignore it, just wait 20ms
if (A_TimeSincePriorHotkey != "" and A_TimeSincePriorHotkey < Threshold)
{
flog "Waiting before up"
sleep 20
}
; If it is no longer pressed, send button up. If it's still down, don't send button up
; This combination ensures that drag & drop works properly even in a double-click scenario
if (!GetKeyState("LButton", "P"))
{
sendinput "{Blind}{LButton up}"
}
}
; file log
flog(params*) {
if (LogFilePath != "") {
ts := FormatTime(, "yyyy-MM-dd HH:mm:ss.") substr(A_TickCount, -3)
; s := A_TickCount
; ts := substr(s,-6,3) "." substr(s,-3)
for , param in params
message .= param . " "
FileAppend ts " " message "`n", LogFilePath
}
}