title: Detect onKeyPress for 2 keys in React
body: <p>I have an <code>input</code> element with the <code>onKeyPress</code> property on it.</p>
  
  <p><code>&lt;input type="text" onKeyPress={this.keyPressed}</code></p>
  
  <p>I want to know when <strong>Enter</strong> or <strong>Escape</strong> is pressed and act accordingly.</p>
  
  <pre><code>keyPressed: function(e) {
  
      if (e.key == 'Enter') {
          console.log('Enter was pressed!');
      } 
      else if (e.key == 'Escape') {
          console.log('Escape was pressed!');
      } 
      else {
          return;
      }
  }
  </code></pre>
  
  <p>I am able to detect when <strong>Enter</strong> is pressed but NOT when <strong>Escape</strong> is.</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <ul>
  <li>e.charCode == 27 ( Not working )</li>
  <li>e.keyCode == 27 ( Not working )</li>
  <li>e.key == 'Escape' ( Not working )</li>
  <li>e.key == 'Esc' ( Not working )</li>
  </ul>
  
  <hr>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have managed to get it working.<br>
  Check my answer: <a href="https://stackoverflow.com/questions/42164802/detect-onkeypress-for-2-keys-in-react#42165140">HERE</a></p>