Page 1 of 1
Mouse hook misses first event after a key press
Posted: Thu Jun 10, 2021 8:34 am
by firace
Not sure what is going on here... This mouse hook detects left clicks just fine, except if a click occurs right after a keypress.
Can anyone confirm? (Win 10 x64, PB 5.73 LTS)
Code: Select all
Procedure MouseHook(nCode, wParam, lParam)
Select wParam
Case #WM_LBUTTONDOWN
AddGadgetItem(1, -1, "Left Mouse Clicked " + Date())
EndSelect
ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
EndProcedure
OpenWindow(0, 0, 0, 240, 320, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
EditorGadget(1, 10, 10, 180, 200)
StringGadget(0, 10, 230, 180, 20, "") : SetActiveGadget(0)
hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @MouseHook(), GetModuleHandle_(0), 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Mouse hook misses first event after a key press
Posted: Thu Jun 10, 2021 9:01 am
by Crusiatus Black
I can't seem to reproduce this in x64 PureBasic 5.72,
where are you clicking when this seems to happen?
Maybe another application is not calling the next hook in the chain in certain situations.
Re: Mouse hook misses first event after a key press
Posted: Thu Jun 10, 2021 9:09 am
by firace
Crusiatus Black wrote: Thu Jun 10, 2021 9:01 am
I can't seem to reproduce this in x64 PureBasic 5.72,
where are you clicking when this seems to happen?
Maybe another application is not calling the next hook in the chain in certain situations.
Strange. I'm clicking inside the test window itself. (I have just updated the code in the top post for easier testing.)
I have no other visible applications open - I'm almost suspecting a hardware or driver issue.
Re: Mouse hook misses first event after a key press
Posted: Thu Jun 10, 2021 9:11 am
by RASHAD
Hi
Did the test before your changes
Works fine no problem
Code: Select all
Procedure MouseHook(nCode, wParam, lParam)
Select wParam
Case #WM_LBUTTONDOWN
SetGadgetText(0,"Left Mouse Clicked "+ Str(Date()))
EndSelect
ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
EndProcedure
OpenWindow(0, 0, 0, 300, 140, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 280, 20, "")
hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @MouseHook(), GetModuleHandle_(0), 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Edit : Works fine even with the renew post
I suggest to use Local Hook better
Code: Select all
Procedure MouseHook(nCode, wParam, lParam)
Select wParam
Case #WM_LBUTTONDOWN
SetGadgetText(0,"Left Mouse Clicked "+ Str(Date()))
EndSelect
ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
EndProcedure
OpenWindow(0, 0, 0, 300, 140, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 280, 20, "")
lpdwProcessId = GetWindowThreadProcessId_(WindowID(0), 0)
hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE, @MouseHook(), GetModuleHandle_(0), lpdwProcessId)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
UnhookWindowsHookEx_(hhkLLMouse)
Re: Mouse hook misses first event after a key press
Posted: Thu Jun 10, 2021 9:34 am
by firace
Just found out something: it works fine if i wait for a second (after my last keypress) before clicking.
So the hook only misses the first mouse event if it occurs too quickly after a keypress.
Also, I just observed the same behavior on a different laptop! So, this seems to rule out a hardware or driver issue.
Anyway, not a big deal, just strange...