ten1seven / what-input

A global utility for tracking the current input method (mouse/pointer, keyboard or touch).
https://ten1seven.github.io/what-input
MIT License
1.35k stars 89 forks source link

Extended mouse identification #16

Closed meibegger closed 8 years ago

meibegger commented 8 years ago

Hi, if you use the keyboard and then scroll with the mouse-wheel or move the mouse without leaving the window, currently the mouse-input is not identified, which is inconsistent. So i think it might be useful to extend the mouse-identification by the wheel and mousemove events. What do you think? Should i extend your widget?

ten1seven commented 8 years ago

Mousewheel event detection is a good call. That should be simple to add.

I've been debating for a long time about using mousemovebecause of the potential expense of an event that fires continually. Debouncing would obviously be necessary. Using mouseenter was a concession, but you're right that it doesn't cover all use cases. I'm going to take a look at this later this week.

meibegger commented 8 years ago

I forked what-input and added wheel & mousemove-support. Both with a debounce. (https://github.com/meibegger/what-input/blob/master/what-input.js) You could merge it if you want. I hope you don't mind!

ten1seven commented 8 years ago

This looks good! I have one comment and one question:

meibegger commented 8 years ago

You are right! I removed mouseenter-detection. According to MDN mousewheel is deprecated (https://developer.mozilla.org/en-US/docs/Web/Events/wheel) and not very widely supported (https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel#Browser_compatibility) ... ?

ten1seven commented 8 years ago

Yea, looks like https://developer.mozilla.org/en-US/docs/Web/Events/wheel is the way to go. The code block on that page is more robust than we need, but maybe there's something in this block for basic detection we can use:

support = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel"
              document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
              "DOMMouseScroll"; // let's assume that remaining browsers are older Firefox
meibegger commented 8 years ago

done : )

meibegger commented 8 years ago

Hi, do you want to merge our "fix" or do you want to provide a different solution, or what is the plan?

ten1seven commented 8 years ago

Hey @meibegger, sorry for the delay. I got buried under some project work over the past month but wanted to have time to test your fix before merging it in. I should be able to get to this in the next week.

ten1seven commented 8 years ago

Just published version 1.2.0 and rolled in some refactoring with the way mouse wheel is implemented.

meibegger commented 8 years ago

Hey @ten1seven. Great!