title: Javascript: triggering button on keydown
body: <p>I'm building a musical e-learning thing, and wish to trigger an input button using the keyboard, which will play an assigned note. Just like a piano! Except this one will make your ears bleed, but that's beside the point.</p>
  
  <p>The onclick() itself works when pressing the button manually, but binding to the keyboard is proving difficult.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="button" id="pgC" value="C" onClick="pgC()"&gt;
  &lt;input type="button" id="pgCsharp" value="C#" onClick="pgCsharp()"&gt;
  </code></pre>
  
  <p>Script to bind to keyboard:</p>
  
  <pre><code>$(function() {
  $(document).keydown(function(e) {
      switch (e.keyCode) {
      case 65:
          $('#pgC')[0].onclick();
          break;
      case 87:
          $('#pgCsharp')[0].onclick();
          break;
      }
   });
  });
  </code></pre>
  
  <p>Which I attempted to modify from this: <a href="https://stackoverflow.com/questions/10541606/binding-keyboard-to-onclick-event">Binding Keyboard to Onclick Event</a></p>
  
  <p>My understanding is that <code>$('#pgC')[0].onclick();</code> should find the assigned id, and trigger the onclick based on which key is pressed, in this case a lower case "a".</p>
  
  <p>Any and all help is greatly appreciated! :D</p>