Search code examples
jqueryhtmlkeyboard-shortcutshotkeys

Set accesskey to keyboard numeric pad keys with jQuery


I'm developing a Web App with HTML5 and jQuery 1.10. I'm using the accesskey attribute in inputs and links to improve the navigation.

Actually I have this code:

    $("#linktabCost").attr("accesskey", "1");
    $("#linktabCapture").attr("accesskey", "2");
    $("#linktabInvoice").attr("accesskey", "3");

With this code, the accesskeys are working as follows:

enter image description here

My question is:

How can I set the accesskey to the numbers of the keyboard numeric pad with jQuery?


Solution

  • I was able to solve this issue with the shortcut.js library and adding the numeric pad keys (97,98,99...) to the library special_keys array.

    var special_keys = {
                    'numpad_1': 97,
                    'numpad_2': 98,
                    'numpad_3': 99,
                    'numpad_4': 100,
                    'numpad_5': 101,
                    'esc':27,
                    'escape':27,
                    'tab':9,
                    'space':32,
                    'return':13,
                    'enter':13,
                    'backspace':8
                     ...
    }
    

    I used this post to solve the problem