Search code examples
javascriptbarcode-scanner

Detect when input box filled by keyboard and when by barcode scanner.


How I can programmatically detect when text input filled by typing on keyboard and when it filled automatically by bar-code scanner?


Solution

  • Well a barcode won't fire any key events so you could do something like:

    $('#my_field').on({
        keypress: function() { typed_into = true; },
        change: function() {
            if (typed_into) {
                alert('type');
                typed_into = false; //reset type listener
            } else {
                alert('not type');
            }
        }
    });
    

    Depending on when you want to evaluate this, you may want to do this check not on change but on submit, or whatever.