title: keypress event handler but on a windows app with no forms
body: <p>I have an application that is tied to a card reader (magnetic strip).  I've able to capture the data on the cards when I have a form that outputs my data or in a console application where I can output the data to the console.</p>
  
  <p>But on the app I'm working on it has a Program class as its startup and just starts the program that way.</p>
  
  <p>What I think I need is a generic keypress listener to look for when the card reader is swiped.</p>
  
  <p><a href="https://stackoverflow.com/questions/5413500/catch-input-from-a-magnetic-card-reader-to-a-variable">Windows Forms App Ex</a>
  <a href="https://stackoverflow.com/questions/8898182/how-to-handle-key-press-event-in-console-application">Console App Ex</a>
  <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.keypresseventhandler.aspx" rel="nofollow noreferrer">KeyPressEventHandler Delegate</a></p>
  
  <p>I think I want something like the KeyPressEventHandler but I can't seem to get that to work in my application.</p>
  
  <p>I've created the following Extention method:</p>
  
  <pre><code>public static class Utilities
  {
      private static KeyPressEventHandler handler = KeyPressed;
  
      public static void KeyPressed(Object sender, KeyPressEventArgs e)
      {
          while (true)
          {
              dataReceived.Append(e.KeyChar);
          }
      }
  
      public static KeyPressEventHandler getKeyPressHandler()
      {
          return handler;
      }
  }
  </code></pre>
  
  <p>But I'm unsure of how to reference it in my <code>Main()</code> method.  I don't see a keypress method.  </p>