In this Article, I’ll explain how to disable some of the Keyboard short key(s) using JavaScript. In the same way you could disable almost any key in a web page
Mainly, the solution is to use key codes for each key in a keyboard.
for e.g.,
Key code for F5 is 116
Key code for backspace is 8
Don’t worry I will tell you how you can find the key code for various keys in a key board at the end !!
also you can make use of event object like “event.ctrlKey” to check if ctrlKey has been pressed
Now Let’s the see the code
You would also want backspace key to work when its placed/focused in a textbox or textarea html elements in a webpage and want to disable only when its outside of those elements. Code for this is
Now, Let’s see how we can find a Key codes for all keys in a keyboard
w3c has built a web page which helps in looking up “Key and Character Codes vs. Event Types”
The below screenshot shows when a key is pressed how the various key code, event details are populated ! This page is very handy
Now block the keys and rock the web
All the Best !!!



