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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -