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.
The onclick() itself works when pressing the button manually, but binding to the keyboard is proving difficult.
HTML:
<input type="button" id="pgC" value="C" onClick="pgC()">
<input type="button" id="pgCsharp" value="C#" onClick="pgCsharp()">
Script to bind to keyboard:
$(function() {
$(document).keydown(function(e) {
switch (e.keyCode) {
case 65:
$('#pgC')[0].onclick();
break;
case 87:
$('#pgCsharp')[0].onclick();
break;
}
});
});
Which I attempted to modify from this: Binding Keyboard to Onclick Event
My understanding is that $('#pgC')[0].onclick();
should find the assigned id, and trigger the onclick based on which key is pressed, in this case a lower case "a".
Any and all help is greatly appreciated! :D