1

How to determine when an accesskey is pressed - with javascript(IE, Chrome, Opera, Safari). In FF I used document.onkeypress event, but in Chrome this event doesn't fire when ALT key is pressed.

Thanks in advance :).

PeterF
  • 61
  • 1
  • 8

1 Answers1

0

Take a look at how it is done in http://plugins.jquery.com/project/KeyTips. This is an excellent library for visually displaying what accessKeys are assigned to what HTML elements.

The key section of code is --

$(document)
.bind("keydown.keytips", function (e) {
    if (!accessKeysHighlighted && (
            (e.keyCode == 18 && !requiresShiftAlt) ||
            (e.keyCode == 16 && e.altKey && requiresShiftAlt) ||
            (e.keyCode == 18 && e.shiftKey && requiresShiftAlt))) {
        // Highlight all the access keys
        highlightAccessKeys();
        //accessKeysHighlighted = true;
    }
})
.bind("keyup.keytips", function (e) {
    // Un-highlight access keys
    if (accessKeysHighlighted) {
        unhighlightAccessKeys();
        //accessKeysHighlighted = false;
    }
});
photo_tom
  • 7,292
  • 14
  • 68
  • 116