Funcionou!
Coloquei um contador de tempo.
Caso seja informado 4 teclas em 1 centésimo de segundo ou menos é interpretado como informado pelo leitor de código de barras, caso o tempo for maior é interpretado como entrada por teclado.
Acredito que ninguém consegue digitar 4 números ou mais em 1 centésimo de segundo.
Obrigado.
============================
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>
<body>
<div name="posicao"></div>
<input type="text" name="teclado">
<div name="buffer"></div>
<input type="text" id="txt">
<div name="posicaoTime"></div>
<div name="tempo"></div>
<h3 style="font-size: 30px;"></h3>
</body>
<script type="text/javascript">
var dados = new Array();
var time = new Array();
var tempoFinal;
var tempoInicio;
var tempo;
var valor = Number(0);
var a = 1;
var posicao = 0;
var x = 0;
function startCount(){
$('#txt').val(a);
a = a + 1;
x = setTimeout("startCount()",(100));
}
function stopCount(){
clearTimeout(x)
}
function buffer(entrada){
posicao = dados.length;
dados[posicao] = entrada;
posicaoTime = time.length;
time[posicaoTime] = a;
var string = "";
var stringTime = "";
$('div[name="posicao"]').html("Posição: " + posicao);
$('div[name="posicaoTime"]').html("PosiçãoTime: " + posicaoTime);
if(dados.length > 4){
tempoInicial = time[0];
tempoFinal = time[time.length-1];
tempo = tempoFinal - tempoInicial;
if(tempo <= 1){
$('h3').html("Você usou o leitor = " + tempo);
}else{
$('h3').html("Você usou o teclado = " + tempo);
}
}else{
$('h3').html("");
}
$.each(dados, function(index, value) {
if(value==9){
dados.length = 0;
time.length = 0;
$('input[name="teclado"]').val("");
}else{
string = string.concat(value);
}
$('div[name="buffer"]').html(string);
});
$.each(time, function(index, value) {
stringTime = stringTime.concat(value);
$('div[name="tempo"]').html(stringTime);
});
}
$('input[name="teclado"]').keydown(function(e) {
buffer(e.keyCode);
});
$(document).ready( function(){
startCount();
$('input[name="teclado"]').focus();
});
$('#txt').focus( function(){
$('input[name="teclado"]').focus();
});
</script>
</html>
============================