Javascript keyevent and JAWS screen reader

邮差的信 提交于 2019-12-21 05:51:03

问题


I have an application that does something (eg alert) each time a spacebar is pressed. This works fine if I am not using JAWS screen reader. However, once I load JAWS screen reader, it does not execute alert when I press the spacebar. I need to use JAWS so I need this to work. Here is the code snippet.

$(document).keypress(function(event) {
    var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
    if (chCode == 32){ //32 is keyCode for spacebar
      alert("spacebars!!!");
    }
});

From my observation, it seems JAWS grabs the keyboard focus and wouldn't allow the spacebar event to fire. JAWS always reads "Space" when I press the spacebar but the alert event does not fire. How can I still get the alert or doSomething() to fire when the spacebar is pressed? How can I take control from JAWS or maybe share keyboard control with JAWS such that even though JAWS reads out the character I pressed (in this case Spacebar), it will allow my event (alert) to fire. Thanks.

More code:

$(document).keypress(function(event) {
  var cc= ('charCode' in event) ? event.charCode : event.keyCode;       
       if (cc == 32)
    {
      spArray.push(Number(new Date()));
    }
});

回答1:


In general, it is not advisable to over-ride screen readers, even if they let you. There are quite a few JAWs keyboard commands (in conjunction with INS) that use the spacebar, and you'd probably lock those commands out.

If the area is primarily formed controls or interactive widgets then you could wrap it in an element with role="application". That puts a (windows) screen reader into 'forms' mode, where keys are passed through to the web-page.

Do not wrap everything in role="application", just the interactive area.

Update: With more information, this is about an audio-based capture where the user triggers an audio file, then triggers something again to set a time and pass the capture.

Using a native button, Jaws will pass through the use of enter (not sure about space, that isn't the usual 'activate' key). I'd suggest either checking for enter key (charcode 13 I think), or even onclick should work. On a native button/link it works across screen readers.

$(document).click(function() {
   spArray.push(Number(new Date()));
});

Assuming that's in the right location so that it doesn't become active until needed. (JS isn't my strong point, but go with the enter key or onclick.




回答2:


An event handler declared like this works in our application:

doKeyDown_: function (evt) {
    var key = evt.keyCode || evt.which;
    //arrows
    if (key == 27 || (key >= 37 && key <= 40)) {
        try {
            if (key >= 37 && key <= 40) {
                this.handleArrwos(evt);
            } else {
                this.handleEsc(evt);
            }
        ...

Although it is based on the ZK platform, the inner engine is still JQuery. Please note that the event is keyDown (not keyPress) and how the pressed key is detected. The example is for Esc and arrow keys - Space should be no problem.

As for accessibility, our etire page is declared as role="application", since the entire content is a dynamically generated page, it's really an application. Only this way Jaws doesn't eat up about any possible keys combination.



来源:https://stackoverflow.com/questions/23064334/javascript-keyevent-and-jaws-screen-reader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!