←back to thread

293 points ulrischa | 3 comments | | HN request time: 0.001s | source
1. andy_ppp ◴[] No.42175325[source]
What is the correct way to check if you have a mouse click rather than a keyboard click? I would be tempted to set a module level flag based on what most recently happened - if there was a "mousedown" event more recently we'll set isKeyboard to false and isMouse to true and vice-versa if "keydown" is pressed.

Then we wouldn't need the isInvokedByMouse and isInvokedByKeyboard functions.

Is there a better way? Relying on screen coordinates for this is highly dubious and I would argue a hack.

replies(1): >>42177759 #
2. matijs ◴[] No.42177759[source]
`event.detail` [1] is 0 for keyboard “clicks” and 1 for pointer clicks.

1: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/det...

replies(1): >>42180562 #
3. andy_ppp ◴[] No.42180562[source]
The whole point of the learning from this article is don’t use hacks and make assumptions about what is happening. This is not for that, this is about how many clicks happened. You might get away with it but it’s not good code.