Last active
December 16, 2019 22:00
-
-
Save zedxxx/eaef29ab4cfc367d715556511e3a3de7 to your computer and use it in GitHub Desktop.
MouseClickFix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program MouseClickFix; | |
uses | |
Windows, | |
Classes, | |
SysUtils, | |
Messages; | |
var | |
mHook: HHook = 0; | |
gLastTime: DWORD = 0; | |
type | |
TMSLLHOOKSTRUCT = packed record | |
pt : TPoint; | |
mouseData : DWord; | |
flags : DWord; | |
time : DWord; | |
dwExtraInfo : PDWord; | |
end; | |
PMSLLHOOKSTRUCT = ^TMSLLHOOKSTRUCT; | |
const | |
THRESHOLD = 40; | |
function LowLevelMouseProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): Longint; stdcall; | |
var | |
VBlock: Boolean; | |
VHookStruct: PMSLLHOOKSTRUCT; | |
VCurrentTime: DWORD; | |
VElapsedTime: DWORD; | |
begin | |
if nCode < 0 then begin | |
Result := CallNextHookEx(mHook, nCode, wParam, lParam); | |
Exit; | |
end; | |
VBlock := False; | |
if nCode = HC_ACTION then begin | |
VHookStruct := PMSLLHOOKSTRUCT(lParam); | |
VCurrentTime := VHookStruct.time; | |
VElapsedTime := VCurrentTime - gLastTime; | |
if wParam = WM_LBUTTONDOWN then begin | |
if VElapsedTime < THRESHOLD then begin | |
VBlock := True; | |
end; | |
end else if wParam = WM_LBUTTONUP then begin | |
glastTime := VCurrentTime; | |
end; | |
end; | |
if VBlock then begin | |
Result := 1; | |
end else begin | |
Result := CallNextHookEx(mHook, nCode, wParam, lParam); | |
end; | |
end; | |
const | |
WH_MOUSE_LL = 14; | |
var | |
VMsg: TMsg; | |
begin | |
mHook := SetWindowsHookEx(WH_MOUSE_LL, @LowLevelMouseProc, hInstance, 0); | |
while GetMessage(VMsg, 0, 0, 0) do begin | |
TranslateMessage(VMsg); | |
DispatchMessage(VMsg); | |
end; | |
UnhookWindowsHookEx(mHook); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment