diff --git a/what-input.js b/what-input.js index fe77079..20ec469 100644 --- a/what-input.js +++ b/what-input.js @@ -92,7 +92,7 @@ window.whatInput = (function() { */ // allows events that are also triggered to be filtered out for `touchstart` - function eventBuffer() { + function eventBuffer(event) { clearTimer(); setInput(event); @@ -212,8 +212,8 @@ window.whatInput = (function() { body.addEventListener(mouseWheel, bufferedEvent); // keyboard events - body.addEventListener('keydown', unBufferedEvent); - body.addEventListener('keyup', unBufferedEvent); + body.addEventListener('keydown', eventBuffer); + body.addEventListener('keyup', eventBuffer); document.addEventListener('keyup', unLogKeys); } diff --git a/what-input.min.js b/what-input.min.js index e01dbea..0d8cc05 100644 --- a/what-input.min.js +++ b/what-input.min.js @@ -4,4 +4,4 @@ * @link https://github.com/ten1seven/what-input * @license MIT */ -window.whatInput=function(){"use strict";function e(){o(),i(event),f=!0,l=window.setTimeout(function(){f=!1},650)}function t(e){f||i(e)}function n(e){o(),i(e)}function o(){window.clearTimeout(l)}function i(e){var t=u(e),n=L[e.type];if("pointer"===n&&(n=d(e)),m!==n){var o=document.activeElement.nodeName.toLowerCase();!w.hasAttribute("data-whatinput-formswitching")&&!w.hasAttribute("data-whatinput-formtyping")&&m&&h.indexOf(o)>-1||E.indexOf(t)>-1||r(n)}"keyboard"===n&&a(t)}function r(e){m=e,w.setAttribute("data-whatinput",m),-1===k.indexOf(m)&&k.push(m)}function u(e){return e.keyCode?e.keyCode:e.which}function d(e){return"number"==typeof e.pointerType?M[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType}function a(e){-1===v.indexOf(b[e])&&b[e]&&v.push(b[e])}function s(e){var t=u(e),n=v.indexOf(b[t]);-1!==n&&v.splice(n,1)}function c(){w=document.body,window.PointerEvent?(w.addEventListener("pointerdown",t),w.addEventListener("pointermove",t)):window.MSPointerEvent?(w.addEventListener("MSPointerDown",t),w.addEventListener("MSPointerMove",t)):(w.addEventListener("mousedown",t),w.addEventListener("mousemove",t),"ontouchstart"in window&&w.addEventListener("touchstart",e)),w.addEventListener(y,t),w.addEventListener("keydown",n),w.addEventListener("keyup",n),document.addEventListener("keyup",s)}function p(){return y="onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"}var w,v=[],f=!1,m=null,h=["button","input","select","textarea"],y=p(),E=[16,17,18,91,93],L={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch"};L[p()]="mouse";var l,k=[],b={9:"tab",13:"enter",16:"shift",27:"esc",32:"space",37:"left",38:"up",39:"right",40:"down"},M={2:"touch",3:"touch",4:"mouse"};return"addEventListener"in window&&Array.prototype.indexOf&&(document.body?c():document.addEventListener("DOMContentLoaded",c)),{ask:function(){return m},keys:function(){return v},types:function(){return k},set:r}}(); \ No newline at end of file +window.whatInput=function(){"use strict";function e(e){n(),o(e),m=!0,L=window.setTimeout(function(){m=!1},650)}function t(e){m||o(e)}function n(){window.clearTimeout(L)}function o(e){var t=r(e),n=E[e.type];if("pointer"===n&&(n=d(e)),v!==n){var o=document.activeElement.nodeName.toLowerCase();!p.hasAttribute("data-whatinput-formswitching")&&!p.hasAttribute("data-whatinput-formtyping")&&v&&f.indexOf(o)>-1||y.indexOf(t)>-1||i(n)}"keyboard"===n&&u(t)}function i(e){v=e,p.setAttribute("data-whatinput",v),-1===l.indexOf(v)&&l.push(v)}function r(e){return e.keyCode?e.keyCode:e.which}function d(e){return"number"==typeof e.pointerType?b[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType}function u(e){-1===w.indexOf(k[e])&&k[e]&&w.push(k[e])}function a(e){var t=r(e),n=w.indexOf(k[t]);-1!==n&&w.splice(n,1)}function s(){p=document.body,window.PointerEvent?(p.addEventListener("pointerdown",t),p.addEventListener("pointermove",t)):window.MSPointerEvent?(p.addEventListener("MSPointerDown",t),p.addEventListener("MSPointerMove",t)):(p.addEventListener("mousedown",t),p.addEventListener("mousemove",t),"ontouchstart"in window&&p.addEventListener("touchstart",e)),p.addEventListener(h,t),p.addEventListener("keydown",e),p.addEventListener("keyup",e),document.addEventListener("keyup",a)}function c(){return h="onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"}var p,w=[],m=!1,v=null,f=["button","input","select","textarea"],h=c(),y=[16,17,18,91,93],E={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch"};E[c()]="mouse";var L,l=[],k={9:"tab",13:"enter",16:"shift",27:"esc",32:"space",37:"left",38:"up",39:"right",40:"down"},b={2:"touch",3:"touch",4:"mouse"};return"addEventListener"in window&&Array.prototype.indexOf&&(document.body?s():document.addEventListener("DOMContentLoaded",s)),{ask:function(){return v},keys:function(){return w},types:function(){return l},set:i}}(); \ No newline at end of file