title: Control Key Output to Application with Focus
body: <p>I'm wanting to capture what is being typed and release it at a slower rate. In other words, if someone is typing at 100 wpm, I want the text they are typing to only appear at a rate of 60 wpm.</p>
  
  <p>I've been heavily basing my code off of <a href="http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx" rel="nofollow">this article</a>.</p>
  
  <p><code>CallNextHookEx(_hookID, nCode, wParam, lParam);</code> is what determines if a key appears on the application. I've tried making a custom class like this:</p>
  
  <pre><code>public class KeyOutput
  {
      public int vkcode;
      public int nCode;
      public IntPtr wParam;
      public IntPtr lParam;
      public KeyOutput(int in_vkcode, int in_code, IntPtr in_wParam, IntPtr in_lParam)
      {
          vkcode = in_vkcode;
          nCode = in_code;
          wParam = in_wParam;
          lParam = in_lParam;
      }
      public int Getvkcode
      {
          get
          {
              return vkcode;
          }
      }
      public int Getcode
      {
          get
          {
              return nCode;
          }
      }
      public IntPtr GetwParam
      {
          get
          {
              return wParam;
          }
      }
      public IntPtr GetlParam
      {
          get
          {
              return lParam;
          }
      }
  }
  </code></pre>
  
  <p>I did it in hopes that by saving nCode, wParam, lParam I could simply call <code>CallNextHookEx</code> and it would display the character. When I tried to loop through the items in my <code>List&lt;KeyOutput&gt;</code> it would only display the last character that was pressed and none of the rest.</p>
  
  <p>I've modified <code>HookCallback</code> like so (it currently displays text as they are typing it):</p>
  
  <pre><code>private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
      {
          if (nCode &gt;= 0 &amp;&amp; wParam == (IntPtr)WM_KEYDOWN)
          {
              int vkCode = Marshal.ReadInt32(lParam);
              KeyOutput key = new KeyOutput(vkCode, nCode, wParam, lParam);
              listout.Add(key);
              Console.WriteLine((Keys)vkCode);
          }
  
          if (listout.Count == 8)
          {
              foreach (KeyOutput key in listout)
              {
                  Console.WriteLine((Keys)key.Getvkcode);
                  CallNextHookEx(_hookID, key.Getcode, key.GetwParam, key.GetlParam);
              }
          }
          return CallNextHookEx(_hookID, nCode, wParam, lParam);
      }
  </code></pre>
  
  <p><code>if(listout.Count == 8)</code> is arbitrary and servers no purpose other than testing.</p>
  
  <p>Thank you for any help you may have!</p>