js 条码枪扫描_国外牛人写的检测条码枪输入的js

/*

* onScan.js - scan-events for hardware barcodes scanners in javascript

*/

var onScan = {

attachTo: function(oDomElement, oOptions) {

if(oDomElement.scannerDetectionData != undefined){

throw new Error("onScan.js is already initialized for DOM element " + oDomElement);

}

var oDefaults = {

onScan: function(sScanned, iQty){}, // Callback after detection of a successfull scanning:  function(){sScancode, iCount)}()

onScanError: function(oDebug){}, // Callback after detection of a unsuccessfull scanning (scanned string in parameter)

onKeyProcess: function(sChar, oEvent){}, // Callback after receiving and processing a char (scanned char in parameter)

onKeyDetect: function(iKeyCode, oEvent){}, // Callback after detecting a keyDown (key char in parameter) - in contrast to onKeyProcess, this fires for non-character keys like tab, arrows, etc. too!

onPaste: function(sPasted, oEvent){}, // Callback after receiving a value on paste, no matter if it is a valid code or not

keyCodeMapper: function(oEvent){return String.fromCharCode(oEvent.which)}, // Custom function to decode a keydown event into a character. Must return decoded character or NULL if the given event should not be processed.

onScanButtonLongPress: function(){}, // Callback after detection of a successfull scan while the scan button was pressed and held down

scanButtonKeyCode:false, // Key code of the scanner hardware button (if the scanner button a acts as a key itself)

scanButtonLongPressTime:500, // How long (ms) the hardware button should be pressed, until a callback gets executed

timeBeforeScanTest:100, // Wait duration (ms) after keypress event to check if scanning is finished

avgTimeByChar:30, // Average time (ms) between 2 chars. Used to do difference between keyboard typing and scanning

minLength:6, // Minimum length for a scanning

suffixKeyCodes:[9,13], // Chars to remove and means end of scanning

prefixKeyCodes:[], // Chars to remove and means start of scanning

ignoreIfFocusOn:false, // do not handle scans if the currently focused element matches this selector or object

stopPropagation:false, // Stop immediate propagation on keypress event

preventDefault:false, // Prevent default action on keypress event

reactToKeydown:true, // look for scan input in keyboard events

reactToPaste:false, // look for scan input in paste events

singleScanQty: 1 // Quantity of Items put out to onScan in a single scan

}

oOptions = this._mergeOptions(oDefaults, oOptions);

// initializing options and variables on DomElement

oDomElement.scannerDetectionData = {

options: oOptions,

vars:{

firstCharTime: 0,

lastCharTime: 0,

stringWriting: '',

callIsScanner: false,

testTimer: false,

longPressTimeStart: 0,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值