javascript - How to trigger keyboard events in HTML? -
hello i'm making app need obtain keyboard access use left arrow key , right arrow key of keyboard, app html5 , javascript, it's pretty easy robot class of java, question is... there way javascript ?
you this:
$(document).keydown(function(event){ var key = event.which; switch(key) { case 37: // key left. call function key left work break; case 38: // key up. call function key work break; case 39: // key right. call function key right work break; case 40: // key down. call function key down work break; } });
these keycode arrow values:
left 37 38 right 39 down 40
edit: if want programically press certian key through javascript can this:
jquery.trigger({ type: 'keypress', which: keycode });
Comments
Post a Comment