Effect on System Performance

Oct 13, 2011 at 8:20 AM

Can anyone weigh in on this?

How does this library impact system performance? How does it compare to other libraries or methods for hooking keyboard and mouse events?  Would/does a C++ implementation perform significantly better?

For instance, is it practical to use this library for an always-running application (say, one that resides in the system tray), in order to detect if a user presses a particular hotkey (say, F10), which triggers this always-running application to do something (say, take a screenshot).

Oct 14, 2011 at 4:15 AM

This library is well suited for a tray application.

During alpha development, I ran some tests with RedGate ANTS Performance Profiler. The average memory usage of the demo application was ~250kb, with a peak of 500kb when App/Global hook was swapped - but would return to 250kb upon garbage collection. Small memory footprint is fine.

All implementations of mouse/keyboard hooks use essentially the same method. That is SetWindowsHookEx and do processing in the HookProc (when callback is received). This library is different from others in how the processing is implemented. Other online code that I've seen stays with the skeletal basics of how to detect input, but almost nothing more. In this library with several conditionals and thought-out refactoring, it ensures that events are thrown in standard .Net order, double-clicks are thrown with 100% accurately, and provides custom events/event arguments. While the other skeletal code may be marginally faster (i.e. less code) the time saved by the developer by being able to add an event handler for the HookListener and have a fully loaded EventArgs to work with - is enormous. 

Now about the C++ implementation. Again the same basic SetWindowsHookEx method is employed and there will be some gain in raw processing speed. However, there are drawbacks such as a) continuous interop to an unmanaged DLL b) more difficult to maintain c) if the goal is to provide standard .Net events, C++ isn't well suited. Those are just a few.

Just as an FYI., I'm planning to implement hotkeys (and maybe mouse gestures) in Version 4. This would eliminate your need to use the event handler for KeyDown and check each Keydown that occurs.

Oct 14, 2011 at 4:39 AM

Thanks for the thorough response! Very encouraging information.

P.S. I'm sure other folks that run into this discussion will benefit from your detailed reply.