leenpamyu

CTRL block

Jan 3rd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.92 KB | None | 0 0
  1. <script language="JavaScript">
  2. function disableCtrlKeyCombination(e)
  3. {
  4.     //list all CTRL + key combinations you want to disable
  5.     var forbiddenKeys = new Array('a', 'n', 'u', 'x', 'v', 'j');
  6.     var key;
  7.     var isCtrl;
  8.  
  9.     if(window.event)
  10.     {
  11.         key = window.event.keyCode;     //IE
  12.         if(window.event.ctrlKey)
  13.                         isCtrl = true;
  14.                 else
  15.                         isCtrl = false;
  16.     }
  17.     else
  18.     {
  19.         key = e.which;     //firefox
  20.         if(e.ctrlKey)
  21.             isCtrl = true;
  22.         else
  23.             isCtrl = false;
  24.     }
  25.  
  26.     //if ctrl is pressed check if other key is in forbidenKeys array
  27.     if(isCtrl)
  28.     {
  29.         for(i=0; i<forbiddenkeys .length; i++)
  30.         {
  31.             //case-insensitive comparation
  32.             if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
  33.             {
  34.                 alert('Key combination CTRL + '
  35.                     +String.fromCharCode(key)
  36.                     +' has been disabled.');
  37.                 return false;
  38.             }
  39.         }
  40.     }
  41.     return true;
  42. }
  43. </script>
Advertisement
Add Comment
Please, Sign In to add comment