问题
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
回答1:
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
来源:https://stackoverflow.com/questions/52914854/distinguish-the-keypress-and-click-in-mozilla-when-nvda-is-on