Question: I have an HTML input

```
<input type="text" id="txtInput">

```

and I need to disable all keyboard keys for input, only to allow barcode scanners to get the data of the barcode and fill it with the input.

I tried "readonly" and "disabled" and javaScript keydown, but all those solutions disable everything including barcode scanners too.

Is there's any way for doing this?

Answer: 
```
<script>    
setTimeout('timedRefresh()', 300000);   
setTimeout('refocus()', 1000);      
//********** KEYPRESS PREVENTION
$(document).ready(function(){
    $("#txtInput").keypress(function() {
        setTimeout('refocus()', 700)
    });
}); 

//********** PASTE PREVENTION $(document).ready(function(){
$(document).on("cut copy paste","#txtInput",function(e) {
    e.preventDefault();
    });  
}); 

```

When you press it clears every character. but you can use barcode scanner to key in your text. You are not allowed to paste also. 700ms timeout is what i believe the most optimized time for barcode to keyin the text and press enter.
I found a jquery script that detects input of keyboard vs scanner <https://jsfiddle.net/PhilM/Bf89R/3/> and had it modified to block keyboard entry, paste, and autofill.

in the html I disabled the autofil.

```
   <form autocomplete="off" onsubmit="return false">
  <input type="text" id="scanInput"/>
</form>

```

and then used the query to detect and block keybard and paste entry.

```
let inputStart, inputStop;

$("#scanInput")[0].onpaste = e => e.preventDefault();
// handle a key value being entered by either keyboard or scanner
var lastInput

let checkValidity = () => {
    if ($("#scanInput").val().length < 10) {
      $("#scanInput").val('')
  } else {
    $("body").append($('<div style="background:green;padding: 5px 12px;margin-bottom:10px;" id="msg">ok</div>'))
  }
  timeout = false
}

let timeout = false
$("#scanInput").keypress(function (e) {
  if (performance.now() - lastInput > 1000) {
    $("#scanInput").val('')
  }
    lastInput = performance.now();
    if (!timeout) {
    timeout = setTimeout(checkValidity, 200)
  }
});

```

demo here
<http://jsfiddle.net/uyzsb3o0/8/>