gmamaladze / globalmousekeyhook

This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
MIT License
1.05k stars 257 forks source link

Lag when detecting mouse click #135

Open Sk8ERxPiPE opened 3 years ago

Sk8ERxPiPE commented 3 years ago

My application detects when a mouse button is pressed and triggers an event. There is a noticeable (~200ms?) freeze in the mouse movement when the mouse is clicked. I checked and the other parts of my program aren't causing lag. Is there a way to implement this with minimal (<10ms) freeze in the mouse response? I don't want the cursor to noticeably freeze in place when the user is using the application.

My code: public void Subscribe() { m_GlobalHook = Hook.GlobalEvents(); m_GlobalHook.MouseDown += M_GlobalHook_MouseDown; ; } private void M_GlobalHook_MouseDown(object sender, MouseEventArgs e) { do stuff ... }

Sk8ERxPiPE commented 3 years ago

Actually, looking further, the freezing is coming from a called function that does not freeze when I call from a key event...

Sk8ERxPiPE commented 3 years ago

Ok, so my issue is I detect a mouseDown then I want to as quickly as possible trigger another mouseDown using: inp.mi.dwFlags = mouseButtonDown; SendInput(1, ref inp, Marshal.SizeOf(inp)); but there is about a 300ms freeze when I try to do this. Any recommendations on how to reduce it? When I read a keyboard input using WndProc messages, I don't have this freezing issue.

Sk8ERxPiPE commented 3 years ago

Aaaaand... the issue seems to have resolved itself. Well ok then, wish I could figure out why 😬