js读取usb扫码枪数据功能代码实现
window.onload = function(e){
var code = "";
var lasttime,nexttime;
var lastcode,nextcode;
document.onkeypress = function(e) {
nextcode = e.which;
nexttime = new date().gettime();
if(lastcode != null && lasttime != null && nexttime - lasttime <= 30) {
code += string.fromcharcode(lastcode);
} else if(lastcode != null && lasttime != null && nexttime - lasttime > 100){
code = "";
}
lastcode = nextcode;
lasttime = nexttime;
}
this.onkeypress = function(e){
if(e.which == 13){
console.log(code);
code = "";
}
}
}