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

Bug for `whatInput.ask()` when leaving browser window #130

Open babaric-dev opened 11 months ago

babaric-dev commented 11 months ago
<!DOCTYPE html>
    <html>
        <head>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/what-input/5.2.12/what-input.min.js"></script>
            <title>Testing</title>
    </head>
    <body>
        <label for="textbox">Type here: </label>
        <input name="textbox" id="textbox">
        <p id="inputtype"></p>
        <script>
            const textbox = document.getElementById("textbox");
            const inputtype = document.getElementById("inputtype");
            textbox.addEventListener("input", () => {
                inputtype.innerText = "input: " + whatInput.ask();
            });
            textbox.addEventListener("blur", () => {
                inputtype.innerText = "blur: " + whatInput.ask();
            });
        </script>
    </body>
</html>

Paste the code above into a file and then open it in a browser. Also open another window (doesn't matter what) side by side. Focus to the textbox, type something and then unfocus the browser window. It shows the blur event is triggered, which is indeed correct. But whatInput.ask() should return mouse instead of keyboard.