jQuery Keyboard


/ Published in: jQuery
Save to your folder(s)

note to self.


Copy this code and paste it in your HTML
  1. // Generic setup to capture keyup events in jquery;
  2. // replace console.log with your own functions you want called when a particular keyup event is fired.
  3. // faster if you remove unused cases - this setup is for quick implementation / keycode reference;
  4. // console for firebug - remove
  5.  
  6. if(typeof console == 'undefined'){
  7. console = {};
  8. console.log = function(arg){return false;};
  9. }
  10.  
  11. $(document).keyup(function(e){
  12. switch(e.keyCode){
  13. case 65 : console.log('a'); break; // a
  14. case 66 : console.log('b'); break; // b
  15. case 67 : console.log('c'); break; // c
  16. case 68 : console.log('d'); break; // d
  17. case 69 : console.log('e'); break; // e
  18. case 70 : console.log('f'); break; // f
  19. case 71 : console.log('g'); break; // g
  20. case 72 : console.log('h'); break; // h
  21. case 73 : console.log('i'); break; // i
  22. case 74 : console.log('j'); break; // j
  23. case 75 : console.log('k'); break; // k
  24. case 76 : console.log('l'); break; // l
  25. case 77 : console.log('m'); break; // m
  26. case 78 : console.log('n'); break; // n
  27. case 79 : console.log('o'); break; // o
  28. case 80 : console.log('p'); break; // p
  29. case 81 : console.log('q'); break; // q
  30. case 82 : console.log('r'); break; // r
  31. case 83 : console.log('s'); break; // s
  32. case 84 : console.log('t'); break; // t
  33. case 85 : console.log('u'); break; // u
  34. case 86 : console.log('v'); break; // v
  35. case 87 : console.log('w'); break; // w
  36. case 88 : console.log('x'); break; // x
  37. case 89 : console.log('y'); break; // y
  38. case 90 : console.log('z'); break; // z
  39. }
  40. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.