Disable keyboard keys using javascript or jquery

21

Javascript/Jquery snippet to disable keyboard keys on a webpage. You can also allow a particular key like enter key and disable the rest

Disable keyboard keys using jquery

Allowing certain keyboard buttons and disabling the rest. In this case allowing the windows key using jquery.

Disable keyboard keys using javascript

Allowing certain keyboard buttons and disabling the rest. In this case allowing the windows key using javascript.

Part of the code has been taken from this post. Key codes list can be found here.

Share.
 

About Author

Entrepreneur & Dreamer

I am a passionate Software Professional, love to learn and share my knowledge with others.

Software is the hardware of my life.

21 Comments

  1. //To disable a particular key:

    window.addEventListener(“keydown”, function (e) {

    if ([key code1,key code2 …].indexOf(e.keyCode) > -1) {
    e.preventDefault();
    }
    }, false);

  2. Hi,
    i have one problem to disable shortcut keys in chrome and firefox browsers,…

    browser event ctrl+n – i need disable and execute my function in my web page.

    Thanks in advance
    Kannan – Developer

Leave A Reply

CommentLuv badge

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.