title: Keyboard hooks in C#: Side-effects
body: <p>I have seen a number of questions on this topic on SO and elsewhere, but I've now taken it a step further and am facing some weird behavior.</p>
  
  <p>My application (an Excel add-in) installs a keyboard hook to monitor for <kbd>ENTER</kbd> key to perform some actions. The hook appears to works, as it executes the procedure I have wired with it when user presses <kbd>ENTER</kbd>. However, I see 2 strange behaviors:</p>
  
  <ol>
  <li>The NumLock status turns off automatically after my hooked procedure has executed.</li>
  <li>A library that my add-in is using throws <code>SEHException</code> (with message "External component threw an exception"). If I do not install the hook, the library works fine.</li>
  </ol>
  
  <p>So I'm wondering if there's something wrong with the hook itself. I have downloaded it from a <a href="http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook" rel="nofollow">CodeProject article</a>, but looking at some other implementations, most of these have the same basic code.</p>