0

I am working with some others on a web based javascript game, and there is a small issue where occasionally keyboard shortcuts can get in the way. sometimes for example, one might accidentally press Alt+W and that can be annoying (and sometimes a little scary depending on what your doing). So i would like to know, is there any way to use javascript to disable shortcuts on a webpage? i have looked around quite a lot and have not found anything about how to do this

  • Take a look at https://stackoverflow.com/a/53855603/16688813 and you can also search for `Alt` keycode – Tom Nov 16 '21 at 17:07

1 Answers1

0

you need to use key codes. try with something like this:

window.onload = function() {
    window.document.body.onkeydown = function() {
        if (event.ctrlKey) {
            event.stopPropagation();
            event.preventDefault();
            try {
                event.keyCode = 0;
            }
            catch (event) {

            }
            return false;
        }
        return true;
    }
}
AnC Dev
  • 141
  • 12