A global utility for tracking the current input method (mouse, keyboard or touch).
What Input adds data attributes to the tag based on the type of input being used.
It also exposes a simple API that can be used for scripting interactions.
GET IT:npm install --save what-input
Sample usage:
123456789101112131415
whatInput.ask();// returns `mouse`, `keyboard` or `touch`whatInput.types();// ex. returns ['mouse', 'keyboard']whatInput.ask('loose');// returns `mouse` because mouse movement was detectedmyButton.addEventListener('click',function(){if(whatInput.ask()==='mouse'){// do mousy things}elseif(whatInput.ask()==='keyboard'){// do keyboard things}});
Event mapping:
1234567891011
// mapping of events to input typesconstinputMap={'keyup':'keyboard','mousedown':'mouse','mousemove':'mouse','MSPointerDown':'pointer','MSPointerMove':'pointer','pointerdown':'pointer','pointermove':'pointer','touchstart':'touch'};