How to get the keyboard key value with jQuery and run a custom action


This is probably the simplest way to capture the key that the user pressed and execute an action (in this case just a simple

(function() {

    function customAction() {"You have pressed an 'a' in your keyboard");

    $(window).on('keypress', function(event) {

        // keyCode te da el código de la tecla que presiones
        if (event.keyCode === 97) { // The 'a' key was activated


That’s it, enjoy it!

Leave a Reply

Your email address will not be published. Required fields are marked *