title: What does WPF use to capture mouse and keyboard input?
body: <p>I globally (system-wide) filter certain mouse clicks using <code>SetWindowsHookEx</code> and <code>WH_MOUSE_LL</code>. The problem is it doesn't work for WPF applications (all WPF applications detect mouse clicks whether or not I have instructed the system to ignore these clicks). I've already asked a <a href="https://stackoverflow.com/questions/3223406/low-level-mouse-hook-and-directx">similar question here</a>, but I made an assumption that WPF uses <code>DirectInput</code> instead of standard Windows messages for detecting the input. But does it?</p>
  
  <p>I've been able to find a code that was able to <a href="https://stackoverflow.com/questions/1371279/injecting-mouse-input-in-wpf-applications">inject mouse clicks into WPF applications using <code>SendMessage</code></a>. If that's possible, then I think it somehow means WPF does not use <code>DirectInput</code> for mouse input. But then, why it's not possible to prevent WPF applications from detecting mouse clicks with <code>SetWindowsHookEx</code>?</p>
  
  <p>Although this question is mainly about the mouse input, I would also like to know how it works for keyboard input as well.</p>
  
  <h2>Example</h2>
  
  <p>I've quickly created the following solution to reproduce the odd WPF behavior. It consists of 3 projects:</p>
  
  <ul>
  <li><p><strong>HookTester</strong><br>
  StartUp project, automatically launches other 2 projects, so you should be mainly concerned about this one. Installs mouse hook when launched, and uninstalls the hook when you close the form.</p></li>
  <li><p><strong>WinFormsTest</strong><br>
  Contains a TextBox with default context menu where you can test the right mouse button. When the HookTester is running, you should not be able invoke the context menu using right mouse button.</p></li>
  <li><p><strong>WpfTest</strong><br>
  Contains a TextBox as well, with custom context menu (although I could use default menu as well), so this is again the place to test right mouse button. You should not be able to invoke the context menu (using right mouse button) as long as HookTester is running, but for some reason, the menu will be showed anyway (Why???).</p></li>
  </ul>
  
  <p><strong>WARNING:</strong> When you run the solution, the HookTester project will start and will immediately install the hook to reject any right-buttom mouse clicks (system-wide). You can easily uninstall the hook simply by closing the HookTester form. Test with caution.</p>
  
  <p><strong>Download SO5036143.ZIP:</strong> <a href="http://www.filedropper.com/so5036143" rel="nofollow noreferrer">mirror 1</a>, <a href="http://www.mediafire.com/?vfh1l1jl1udxr65" rel="nofollow noreferrer">mirror 2</a></p>