I am trying to disable all shortkeys when certain keys (Ctrl/Shift) are clicked.
This is my quick snippet:
$(document).keyup(function(b) {
if (b.keyCode == 16) {return false;}
if (b.keyCode == 17) {return false;}
$("body").append(b.keyCode + " ");
});
When ever you click Shift or Click, the keyCode number is not printed but if you click Shift + Any Letter, the keyCode of the letter is printed.
Example: http://jsfiddle.net/javascript/K4sCx/7/
You can determine if a "special keys" was pressed in your event Object.
Detecting specizal keys in your event object:
if (evtobj.altKey || evtobj.ctrlKey || evtobj.shiftKey)
alert("you pressed one of the 'Alt', 'Ctrl', or 'Shift' keys")
}
Code sample:
$(document).keyup(function(evtobj) {
if (!(evtobj.altKey || evtobj.ctrlKey || evtobj.shiftKey)){
if (evtobj.keyCode == 16) {return false;}
if (evtobj.keyCode == 17) {return false;}
$("body").append(evtobj.keyCode + " ");
}
});
Fiddler
$(window).on('keydown',function(event)
{
if(event.keyCode==123)
{
alert('Entered F12');
return false;
}
else if(event.ctrlKey && event.shiftKey && event.keyCode==73)
{
alert('Entered ctrl+shift+i')
return false; //Prevent from ctrl+shift+i
}
else if(event.ctrlKey && event.keyCode==73)
{
alert('Entered ctrl+shift+i')
return false; //Prevent from ctrl+shift+i
}
});
$(document).on("contextmenu",function(e)
{
alert('Right Click Not Allowed')
e.preventDefault();
});
This will supports by Chrome, Firefox, IE and all the browsers for control+shift+i & F12 & right click.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With