79762307

Date: 2025-09-11 19:38:25
Score: 0.5
Natty:
Report link

Although @CodeSmith is absolutely right about the ineffectiveness of such approaches in safeguarding your code, I'm personally not a fan of Root finding why a user might want to do something when it comes to programming questions, so I'll get straight to the answer.

As of now, keyCode is deprecated, unfortunately. The best alternative in my opinion is Code, which has its own limitations too. As mentioned in the official documentation:

“The KeyboardEvent.code property represents a physical key on the keyboard (as opposed to the character generated by pressing the key).”

With that in mind, here's a workaround to block both F12 and Ctrl+Shift+i key combinations.

window.addEventListener('keydown', function(event) {
    if (event.code === 'F12') {
        event.preventDefault();
        console.log('Blocked F12');
    }
    if (event.shiftKey && event.ctrlKey && event.code === 'KeyI') {
        event.preventDefault();
        console.log('Blocked Ctrl + Shift + i');
    }
});

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @CodeSmith
  • Low reputation (0.5):
Posted by: Mehrdad995