Requirement is to distinguish the keypress and mouse click events in Mozilla browser. The condition is that the Mozilla browser should be able to distinguish the events (click and enter) when the NVDA IS TURNED ON
Asked
Active
Viewed 852 times
2
-
The browser will be able to do that anyway regardless of whether a screenreader is turned on [because they are two different event types](https://developer.mozilla.org/en-US/docs/Web/Events). There's not a lot else to go on in your question. Perhaps you could pad it out with some more relevant information. [This answer to a question re checking whether a screenreader is on](https://stackoverflow.com/a/7712758/1377002) might help you too. – Andy Oct 21 '18 at 11:49
-
I agree with @Andy, we need more info. There are situations where some keyboard events will **not** be passed to your object if NVDA is running because NVDA will capture the events, such as up/down arrow keys for walking the DOM, or the quicknav keys like 'H' or 'T'. In those cases, your object would have to have the correct `role` in order to receive those events. But again, more details are needed to really answer this. – slugolicious Oct 22 '18 at 02:42
2 Answers
0
If you're only looking to distinguish between Enter/Space press and mouse/pointer press, I would probably go for using both an onclick
and an onmousedown
.
If the onmousedown
is fired, I would set a flag, that I would read in the onclick
, telling me whether this was actually originally a pointer event.
Something like:
<button onmousedown="pointerFunction()" onclick="clickFunction()">Active this</button>
<script>
var isPointerEvent = false;
function pointerFunction() {
isPointerEvent = true;
// Do something for pointer users
}
function clickFunction() {
if (isPointerEvent) {
return isPointerEvent = false;
}
// Do something for keyboard / screen-reader users
}
</script>
For the record, I posted the same suggestion here for a similar question: https://stackoverflow.com/a/57055357/10494842

Tobias Christian Jensen
- 152
- 10
-
1With a NVDA running, pressing enter or space while focused on the button will actually trigger the onmousedown event. – Colm Shannon Nov 09 '21 at 09:17
-
You can check the detail property of a UI event which records the number of clicks. When a mouseevent is fired from the keyboard via NVDA, detail seems to be 0 https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail – slopps Jun 12 '22 at 00:35