mapping jquery keyboard events - Accessibility

1

I would like to make an accessible menu, which can be retracted with esc and navigable by tab, what would be the best way to do it? for keyup, keydown, would anyone have a good example to mention?

    
asked by anonymous 13.07.2017 / 18:27

1 answer

1

The best way for you to do this is to map the keys you are going to use, as each key has its numbering.

In your case, hold the key pressed, define which DOM element you want to work, that is, you will receive the keyboard event and apply the code you want after key validation.

You can use the Keypress event of the jQuery library, see the example of how to detect the command on the entire page, wherever the cursor is:

$(document).ready(function(){
  $(document).keypress(function(e){
    //Enter
    if(e.wich == 13 || e.keyCode == 13){
        //Botão responsável por exibir a lista do menu;
    }
    // Esc
    if(e.wich == 27 || e.keyCode == 27){
        //Botão responsável por esconder a lista do menu;
    }
  })
});

You can do this using JavaScript or JQuery:

13.07.2017 / 20:42