1

I have a button that is accessed by a keyboard shortcut but the users have to press ALT+Z. Is there anyway to let the users access the button by simply pressing Z (or some other key) without having to press ALT?

Many thanks,

<input style="display:none;" id='stopButton1' type="button" value="Z" onclick="stop('z')" accesskey="z" />
L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
Fred
  • 461
  • 3
  • 9
  • 21

3 Answers3

2

No that is not possible in pure HTML.

JavaScript is needed: Use the keypress event to detect specific character codes, and call some function.

Rob W
  • 341,306
  • 83
  • 791
  • 678
1

We can use jquery 2.1.3 plugin and keypress with ASCII value

JS:

$(document).keypress(function (e) {
    if (e.which == 72 || e.which==104) {
        window.location.replace("http://soluvations.in");
    }
});

HTML:

<p>Press H/h to go to Home Page</p>

Here is JSFIDDLE link

Pradeep Kumar
  • 4,065
  • 2
  • 33
  • 40
1

I landed on this page looking for a quick way to make accesskey operate without the modifier (alt) key.

If anyone else is looking for the same, I have added this to my page:

  $(document).on('keydown', function(e) {
    var link = $("a[accesskey=" + e.key + "]");
    if (link.length) {
      window.location = link.attr('href');
    }
  });

This will capture keypresses, and if there is a link with that accesskey set, it will redirect to its href.

DannyB
  • 12,810
  • 5
  • 55
  • 65