Posted By

mattkenefick on 05/20/08


Tagged

javascript capture keyboard


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jamesming
rafael


Javascript: Keyboard Capture


 / Published in: JavaScript
 

Usage:

  1. var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
  2. var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1);
  3.  
  4. var keyPressed = 0;
  5.  
  6. if(!isIE){
  7. document.captureEvents(Event.KEYPRESS);
  8. }
  9.  
  10. function captureKeyboard(e) {
  11.  
  12. e=e?e:event;
  13.  
  14. document.title = event.keyCode + ' - ' + e.keyCode;
  15.  
  16. if (isIE) {
  17. keyPressed = e.keyCode;
  18. }else{
  19. keyPressed = e.charCode;
  20. }
  21.  
  22. window.status = keyPressed;
  23. return true;
  24.  
  25. }

Report this snippet  

You need to login to post a comment.