robotn / gohook

GoHook, Go global keyboard and mouse listener hook
MIT License
314 stars 44 forks source link

Correct the order of MouseUp and MouseDown #33

Open ldemailly opened 2 years ago

ldemailly commented 2 years ago

Fixes #32 (verified on Windows 11)

ldemailly commented 2 years ago

But this changed break other mouse event, and can't listening MouseDown before drag too.

Sorry I am not following, what does break? (can you give an example)

vcaesar commented 2 years ago

You can click mouse, and the mouse down and up is not right.

ldemailly commented 2 years ago

which os? for me it works with the PR changes on Windows 11

vcaesar commented 2 years ago

Mac os. And the PR should be tested before merge.

ldemailly commented 2 years ago

Well I just tested on Max OS and same, it only works the way I need for my patch

Try:

https://github.com/ldemailly/gohook_sample/blob/main/mouseIssue.go

note that the issue is the missing mouse Up, if you click and hold; the end (release) should be MouseUp and with your original code it's MouseDown

This being said with my patch it's both

with your original code: click and hold, then release:

16:25:04 I mouseIssue.go:20> Mouse Button 1 down (hold)
16:25:05 I mouseIssue.go:27> Mouse Button 1 down event

(ie my issue #32)

with your original code: quick tap/click: (without holding/dragging):

16:26:20 I mouseIssue.go:20> Mouse Button 1 down (hold)
16:26:20 I mouseIssue.go:27> Mouse Button 1 down event
16:26:20 I mouseIssue.go:25> Mouse Button 1 released

with my change: (with the replace in go.mod)

click and hold; then release:

16:28:11 I mouseIssue.go:20> Mouse Button 1 down (hold)
16:28:13 I mouseIssue.go:25> Mouse Button 1 released

which is what I need/expect

but yes quick tap:

16:28:53 I mouseIssue.go:20> Mouse Button 1 down (hold)
16:28:53 I mouseIssue.go:25> Mouse Button 1 released
16:28:53 I mouseIssue.go:27> Mouse Button 1 down event

the down event is unreliable as it's missing anyway when holding

but release should be

ldemailly commented 2 years ago

If you have a better fix for #32 that sounds great and close this one