title: Application.AddMessageFilter - how to read exactly what keys were pushed?
body: <p>I'm experimenting with <a href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&amp;l=EN-US&amp;k=k%28SYSTEM.WINDOWS.FORMS.APPLICATION.ADDMESSAGEFILTER%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK,VERSION=V3.5%22%29;k%28DevLang-CSHARP%29&amp;rd=true" rel="nofollow"><code>Application.AddMessageFilter</code></a>, using some code written originally by Somebody Else, so I don't necessarily understand everything that's happening here.  </p>
  
  <p>Here's what the code looks like.  In <code>Main()</code>:</p>
  
  <pre><code>Application.AddMessageFilter(new KeyDownMessageFilter());
  </code></pre>
  
  <p>In <code>KeyDownMessageFilter</code>:</p>
  
  <pre><code>internal class KeyDownMessageFilter : IMessageFilter {
      private const int WM_KEYDOWN = 0x0100;
  
      public bool PreFilterMessage(ref Message m)
      {
          if (m.Msg == WM_KEYDOWN)
          {
              var k = (Keys)m.WParam;
              var c = (char)k;
              // and some other stuff
          }
          return false;
      }
  }
  </code></pre>
  
  <p>I can see that by casting <code>m.WParam</code> to a variable of type <code>System.Windows.Forms.Keys</code> and then casting that to a <code>char</code>, I can tell which key on the keyboard was pushed.  So far, so good.</p>
  
  <p>BUT - I cannot work out how to tell the difference between a <kbd>Shift</kbd>ed key and a key push without a <kbd>Shift</kbd> - e.g. pushing <kbd>%</kbd> yields the character '5'.  Even more weirdly, looking at the value of the <code>k</code>, it appears as "LButton | MButton | ShiftKey | Space" (no matter whether I push <kbd>5</kbd> or <kbd>%</kbd>).</p>
  
  <p>The MSDN documentation on this subject is rather thin.  Can anyone please explain how to tell exactly what character was pushed, and for bonus marks, explain what this <code>Message</code> object is supposed to be for, and why it uses such nondescript properties such as <code>LParam</code> and <code>WParam</code> to carry useful information?</p>