कुंजीपटल पर टाइप करके भरने वाले टेक्स्ट इनपुट और बार-कोड स्कैनर द्वारा स्वचालित रूप से भरने पर मैं प्रोग्रामेटिक रूप से कैसे पता लगा सकता हूं?पता लगाएं कि कीबोर्ड द्वारा भरने वाले इनपुट बॉक्स और बारकोड स्कैनर द्वारा कब।
उत्तर
खैर एक बारकोड किसी भी महत्वपूर्ण घटनाओं सक्रिय नहीं होगा तो आप की तरह कुछ कर सकता है: जब आप इस का मूल्यांकन करना चाहते पर निर्भर करता है
$('#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');
}
}
});
, आप परिवर्तन पर नहीं बल्कि पर प्रस्तुत इस चेक करने के लिए चाहते हो सकता है , जो कुछ भी।
आप उस इनपुट बॉक्स पर "ऑनकीप" ईवेंट का उपयोग कर सकते हैं। यदि ईवेंट ट्रिगर हुआ है तो आप इसे "कीबोर्ड से इनपुट" कह सकते हैं।
मैंने यह जवाब लिखा, क्योंकि मेरा बारकोड स्कैनर मोटोरोला एलएस 12020 जेनरेट की गई कुंजीपटल घटना है, इसलिए मैं यूटानोस के समाधान का उपयोग नहीं कर सकता।
मेरे समाधान है:
var BarcodeScanerEvents = function() {
this.initialize.apply(this, arguments);
};
BarcodeScanerEvents.prototype = {
initialize: function() {
$(document).on({
keyup: $.proxy(this._keyup, this)
});
},
_timeoutHandler: 0,
_inputString: '',
_keyup: function (e) {
if (this._timeoutHandler) {
clearTimeout(this._timeoutHandler);
this._inputString += String.fromCharCode(e.which);
}
this._timeoutHandler = setTimeout($.proxy(function() {
if (this._inputString.length <= 3) {
this._inputString = '';
return;
}
$(document).trigger('onbarcodescaned', this._inputString);
this._inputString = '';
}, this), 20);
}
};
मैं पता चलता है कि आप अपने बारकोड स्कैनर के लिए एक उपसर्ग सेट कर सकते हैं यदि यह (मैं थोड़ा Vitall कोड बदल):
var BarcodeScanner = function(options) {
this.initialize.call(this, options);
};
BarcodeScanner.prototype = {
initialize: function(options) {
$.extend(this._options,options);
$(document).on({
keyup: $.proxy(this._keyup, this)
});
},
fire: function(str){
$(document).trigger('barcode',str);
},
_options: {timeout: 600, prefixKeyCode: 36, suffixKeyCode: 13, minKeyCode: 32, maxKeyCode: 126},
_isReading: false,
_timeoutHandler: false,
_inputString: '',
_keyup: function (e) {
if(this._isReading){
if(e.keyCode==this._options.suffixKeyCode){
//read end
if (this._timeoutHandler)
clearTimeout(this._timeoutHandler);
this._isReading=false;
this.fire.call(this,this._inputString);
this._inputString='';
}else{
//char reading
if(e.which>=this._options.minKeyCode && e.which<=this._options.maxKeyCode)
this._inputString += String.fromCharCode(e.which);
}
}else{
if(e.keyCode==this._options.prefixKeyCode){
//start reading
this._isReading=true;
this._timeoutHandler = setTimeout($.proxy(function() {
//read timeout
this._inputString='';
this._isReading=false;
this._timeoutHandler=false;
}, this), this._options.timeout);
}
}
}
};
मानक उपसर्ग के साथ उपयोग (होम कुंजी) और प्रत्यय (कुंजी ENTER):
new BarcodeScanner();
...
$(document).on('barcode',function(e,str){
console.log(str);
});
क्या आप समय समाप्त, प्रत्यय, उपसर्ग, न्यूनतम/अधिकतम ascii अनुकूलित की जरूरत है कोड readed:
new BarcodeScanner({timeout: 600, prefixKeyCode: 36, suffixKeyCode: 13, minKeyCode: 32, maxKeyCode: 126});
आप उदाहरण निम्नलिखित कोशिश कर सकते हैं, jQuery प्लगइन का उपयोग कर https://plugins.jquery.com/scannerdetection/
इसकी अत्यधिक विन्यास, समय आधारित स्कैनर डिटेक्टर। इसे उपसर्ग/पोस्टफिक्स आधारित, समय आधारित बारकोड स्कैनर के लिए समाधान के रूप में उपयोग किया जा सकता है।
उपयोग और सर्वोत्तम प्रथाओं के लिए ट्यूटोरियल, साथ ही विभिन्न बारकोड स्कैनर मॉडल और इससे निपटने के तरीके के बारे में चर्चा की गई। http://a.kabachnik.info/jquery-scannerdetection-tutorial.html
$(window).ready(function(){
\t //$("#bCode").scannerDetection();
\t console.log('all is well');
\t
\t $(window).scannerDetection();
\t $(window).bind('scannerDetectionComplete',function(e,data){
console.log('complete '+data.string);
$("#bCode").val(data.string);
})
.bind('scannerDetectionError',function(e,data){
console.log('detection error '+data.string);
})
.bind('scannerDetectionReceive',function(e,data){
console.log('Recieve');
console.log(data.evt.which);
})
//$(window).scannerDetection('success');
<input id='bCode'type='text' value='barcode appears here'/>
धन्यवाद। आपने मेरा दिन बना दिया। मुझे इसकी ही खोज थी। :) –
Vitall से समाधान केवल ठीक काम करता है अगर आप पहले से ही कम से कम एक कुंजी को दबाएँ। यदि आप पहले अक्षर नहीं को अनदेखा कर देंगे (यदि (यह ._timeout हैंडलर) झूठा लौटाता है और चार को जोड़ा नहीं जाएगा)।
आप तुरंत आप निम्नलिखित कोड का उपयोग कर सकते स्कैनिंग शुरू करना चाहते हैं:
var BarcodeScanerEvents = function() {
\t this.initialize.apply(this, arguments);
};
BarcodeScanerEvents.prototype = {
\t initialize : function() {
\t \t $(document).on({
\t \t \t keyup : $.proxy(this._keyup, this)
\t \t });
\t },
\t _timeoutHandler : 0,
\t _inputString : '',
\t _keyup : function(e) {
\t \t if (this._timeoutHandler) {
\t \t \t clearTimeout(this._timeoutHandler);
\t \t }
\t \t this._inputString += String.fromCharCode(e.which);
\t \t this._timeoutHandler = setTimeout($.proxy(function() {
\t \t \t if (this._inputString.length <= 3) {
\t \t \t \t this._inputString = '';
\t \t \t \t return;
\t \t \t }
\t \t \t $(document).trigger('onbarcodescaned', this._inputString);
\t \t \t this._inputString = '';
\t \t }, this), 20);
\t }
};
- 1. पता लगाएं कि उपयोगकर्ता द्वारा
- 2. पता लगाएं कि किसी ऑब्जेक्ट द्वारा पाइथन
- 3. फोनगैप बारकोड स्कैनर
- 4. बारकोड स्कैनर से पढ़ना
- 5. इनपुट बॉक्स में पेस्ट का पता लगाएं
- 6. पता लगाएं कि लिंक कब सक्रिय है - या तो क्लिक या टैब द्वारा और
- 7. स्कैनर उत्पाद आईडी और विक्रेता आईडी को ज्ञात नहीं करते हुए यूएसबी बारकोड स्कैनर का उपयोग करके एक बारकोड पढ़ना
- 8. जावा पर बारकोड स्कैनर कार्यान्वयन
- 9. "प्रतीक" ब्रांड बारकोड स्कैनर और सी #
- 10. यूएसबी बारकोड स्कैनर शोध
- 11. पता लगाएं कि फ़ाइल
- 12. क्वार्ट्ज संगीतकार बारकोड स्कैनर
- 13. पता लगाएं कि इनपुट में 'रीडोनली' विशेषता
- 14. बारकोड स्कैनर? या प्लगइन/एक्सटेंशन
- 15. पता लगाएं कि ओएस एक्स
- 16. पता लगाएं कि पाइथन
- 17. विम में कैसे पता लगाएं कि कमांड
- 18. बारकोड स्कैनर (एंड्रॉइड) कैसे बनाएं?
- 19. उन्नत आईओएस बारकोड स्कैनर लाइब्रेरी?
- 20. पता लगाएं कि फोरग्राउंड विंडो
- 21. पता लगाएं कि डब्ल्यूपीएफ सूचीदृश्य स्क्रॉलबार नीचे कब है?
- 22. माउस या कुंजी द्वारा चुने जाने पर कैसे पता लगाएं?
- 23. पता लगाएं कि
- 24. स्ट्रिंग/उपयोगकर्ता इनपुट भाषा का पता लगाएं
- 25. पता लगाएं कि स्ट्रिंग
- 26. पता लगाएं कि UIScrollView
- 27. पता लगाएं कि लिनक्स
- 28. पता लगाएं कि सी #
- 29. पता लगाएं कि एंड्रॉइड
- 30. पता लगाएं कि हैश
धन्यवाद। लेकिन जब बारकोड इनपुट था तो मैं कैसे पता लगा सकता हूं? 'ऑनेंज' घटना तब बढ़ती है जब तत्व फोकस खो देता है, लेकिन मुझे डालने के तुरंत बाद डालने वाले मूल्य को जानने की आवश्यकता होती है। मैं टाइमर बनाने और समय-समय पर टेक्स्ट फ़ील्ड पर मूल्य की जांच कर सकता हूं, लेकिन मुझे लगता है कि यह गलत समाधान है। – MyTitle
जब आपने इनपुट जांचना चाहते थे तो आपने अपने प्रश्न में उल्लेख नहीं किया था, इसलिए मैंने चेंज पर विचार किया। हां, मुझे लगता है कि एक टाइमर शायद एकमात्र तरीका है, जब तक कि बारकोड एप्लिकेशन किसी प्रकार की कस्टम घटना को तब तक चलाता है जब यह पृष्ठ में हेरफेर करता है। – Utkanos