MouseHookListener stops after a time

Nov 6, 2012 at 6:52 PM

I have tried everything but I didn't find a solution. The mouse Events (MouseDown and MouseUp) stops after a minute working normally. Only when exits the application and entering again the events starts once again.

Any ideas?

Nov 6, 2012 at 8:37 PM

I think it's because you are not holding a reference and it gets garbage collected. I remember there were a similar issue here in this forum earlier. Just go ahead and try to grab it. Otherwise let me know and provide more details about your implementation.

Nov 7, 2012 at 1:58 PM

Thanks for the information.

I have  already tried the solution mentioned in the earlier post in this forum. But do not works for me. The solution mentioned consistis in declare a global instance of MouseHookListener in the main application class. My code is as follows:

namespace InterfaceInterativa
{
    private  MouseHookListener mouseListener;

    public partial class Aplicacao : Form
    {
        mouseListener = new MouseHookListener(new GlobalHooker());
        mouseListener.Enabled = true;
        mouseListener.MouseDownExt += new EventHandler(mouseListener_MouseDownExt);
        .
        .
        .
        .

As I said, after a few seconds, the event "mouseListener_MouseDownExt" stops be called.


Any other suggestion?

Oct 23, 2013 at 4:25 PM
I am having exactly the same symptoms for KeyboardHookListener.KeyPress.

I also have a global class instance of KeyboardHookListener.

As a quick workaround, I'm going to re-instanciate this global variable when the programme is idle (It's being used to capture barcode scans for an EPOS system).

The only difference between my programme and marcilio_junior's is that mine is WPF, not a WinForm application.

I had exactly the same issue with an older version of this Hook library, so I'm betting something is getting garbage collected in the library, rather than our code.

This is really urgent for me, so any help or insight would be greatly appreciated.

Many thanks.

Adam
Oct 24, 2013 at 5:47 PM
Edited Oct 24, 2013 at 5:47 PM
Hi Adam,

First sorry for the bugs and problems we caused in this immature library.
I know it is irresponsible to say that, but would you mind try the latest build if you are currently using V3 Release?
In current upstream, the Disposer has been rewritten to meet the Microsoft Code Analysis Rule sets, and maybe the problem has been implicitly fixed.

The latest binary can be retrieved at https://globalmousekeyhook.codeplex.com/releases/view/113903
APIs remain unchanged, so migration should be seamless.

Chen
Oct 24, 2013 at 5:59 PM
Thanks for the response Chen.

I believe I've found the root cause.

Windows 7 will remove low level hooks that take too long to respond.

I resolved this by adding the registry key below.

Ideally, I will be re-writing the code that processes the low level hook (i.e. KeyPress) by using a background thread.

This reg hack is a quick work around for the moment:

HKEY_CURRENT_USER\Control Panel\Desktop\
LowLevelHooksTimeout=10000 (DWORD)

The timeout is in milliseconds.

See the bottom of the Remarks section on the Microsoft Website
May 30, 2014 at 8:28 AM
You said "it's being used to capture barcode scans for an EPOS system", I am trying to use barcode scanner for creating a membership system. So would you please give me a link for this feature?

Thanks in advance.
May 30, 2014 at 11:25 AM
Hi johnnygold. I'm not sure I understand what you mean by "a link for this feature"?

If by "feature" you mean what is the global variable I'm referring to, then I have a global variable of type KeyboardHookListener.

Let me know if I'm close.