Guest User

Untitled

a guest
Aug 7th, 2020
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Disable Ctrl Key Combinations </title>
  5. <script language="JavaScript">
  6.  
  7. function disableCtrlKeyCombination(e)
  8. {
  9. //list all CTRL + key combinations you want to disable
  10. var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j' , 'w');
  11. var key;
  12. var isCtrl;
  13. if(window.event)
  14. {
  15. key = window.event.keyCode; //IE
  16. if(window.event.ctrlKey)
  17. isCtrl = true;
  18. else
  19. isCtrl = false;
  20. }
  21. else
  22. {
  23. key = e.which; //firefox
  24. if(e.ctrlKey)
  25. isCtrl = true;
  26. else
  27. isCtrl = false;
  28. }
  29. //if ctrl is pressed check if other key is in forbidenKeys array
  30. if(isCtrl)
  31. {
  32. for(i=0; i<forbiddenKeys.length; i++)
  33. {
  34. //case-insensitive comparation
  35. if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
  36. {
  37. alert('Key combination CTRL + '+String.fromCharCode(key) +' has been disabled.');
  38. return false;
  39. }
  40. }
  41. }
  42. return true;
  43. }
  44. </script>
  45. </head>
  46. <body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);">
  47. Press ctrl and you can check various key is disable with CTRL. like — 'a', 'n', 'c', 'x', 'v', 'j' , 'w' Just add key in above the array and disable key as you want.
  48. </body>
  49. </html>
Add Comment
Please, Sign In to add comment