title: Simulating the Enter key in WPF
body: <p>I am trying to simulate a key press in a button event. I can use the code below to simulate some keys such as <kbd>Backspace</kbd>, but the <kbd>Enter</kbd> is not working.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>private void btnEnter_Click(object sender, RoutedEventArgs e)
  {
      tbProdCode.Focus();
  
      KeyEventArgs ke = new KeyEventArgs(
          Keyboard.PrimaryDevice,
          Keyboard.PrimaryDevice.ActiveSource,
          0,
          Key.Enter)
      {
          RoutedEvent = UIElement.KeyDownEvent
      };
  
      InputManager.Current.ProcessInput(ke);
  }
  </code></pre>