Javascript: Keyboard Capture


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

Usage:


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.