title: WPF keyDown response time accuracy
body: <p>I'm developing an application in which user can see something and has to react by clicking a key on the keyboard. Reaction time is crucial and the more accurate the better it is.</p>
  
  <p>I wrote sample app inf WPF only a few lines of code to test default settings:</p>
  
  <pre><code>namespace Test
  {
    /// &lt;summary&gt;
    /// Interaction logic for MainWindow.xaml
    /// &lt;/summary&gt;
    public partial class MainWindow : Window
    {
      private Stopwatch sw; 
      public MainWindow()
      {
          InitializeComponent();
          sw = new Stopwatch();
          sw.Start();
          this.KeyDown += OnKeyDown;
      }
  
      private void OnKeyDown(object sender, KeyEventArgs keyEventArgs)
      {
          sw.Stop();
  
          lbl.Content = sw.ElapsedMilliseconds;
          sw.Restart();
      }
    }
  }
  </code></pre>
  
  <p><code>lbl</code> is a just simple label.</p>
  
  <p>What is strange is that when I press for example space and hold it the value of the <code>lbl</code> changes in the range: 30-33.</p>
  
  <p>So I cant predict what is the response accuracy? Is it impossible to have for example 1 ms accuracy? User hits space and at the same time (for example 1 ms accuracy) I can handle it in the event handler?</p>
  
  <p>The main question is:</p>
  
  <p>let's say I have a key-down event handler:</p>
  
  <pre><code>Test_KeyDown(object sender, KeyEventArgs keyEventArgs)
  {
     time = stopwatch.elapsed();
     stopwatch.Restart();
  }
  </code></pre>
  
  <p>what is the minimum value of "time" that can possibly occur? Can I be sure that the time value is accurate to 1 ms?
  In this method, I start the stopwatch but then I have to wait - how long - for the GUI to refresh? </p>