File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,31 @@ const barcodeHidReader = (function () {
2121 let node
2222 let log
2323
24+ const latinKeyCodes = {
25+ BracketLeft : [ '[' , '{' ] ,
26+ BracketRight : [ ']' , '}' ] ,
27+ Semicolon : [ ';' , ':' ] ,
28+ Quote : [ '\'' , '"' ] ,
29+ Backslash : [ '\\' , '|' ] ,
30+ Comma : [ ',' , '<' ] ,
31+ Period : [ '.' , '>' ] ,
32+ Slash : [ '/' , '?' ] ,
33+ Digit1 : [ '1' , '!' ] ,
34+ Digit2 : [ '2' , '@' ] ,
35+ Digit3 : [ '3' , '#' ] ,
36+ Digit4 : [ '4' , '$' ] ,
37+ Digit5 : [ '5' , '%' ] ,
38+ Digit6 : [ '6' , '^' ] ,
39+ Digit7 : [ '7' , '&' ] ,
40+ Digit8 : [ '8' , '*' ] ,
41+ Digit9 : [ '9' , '(' ] ,
42+ Digit0 : [ '0' , ')' ] ,
43+ Minus : [ '-' , '_' ] ,
44+ Equal : [ '=' , '+' ] ,
45+ Backquote : [ '`' , '~' ] ,
46+ IntlBackslash : [ '\\' , '|' ]
47+ }
48+
2449 function reset ( ) {
2550 timeoutID = undefined
2651 barcode = ''
@@ -124,8 +149,10 @@ const barcodeHidReader = (function () {
124149 )
125150
126151 if ( e . key !== prefix ) {
127- if ( convertToLatin && e . code ?. startsWith ( 'Key' ) ) {
128- barcode += e . shiftKey ? e . code . charAt ( 3 ) : e . code . charAt ( 3 ) . toLowerCase ( )
152+ if ( convertToLatin && ( latinKeyCodes [ e . code ] || e . code ?. startsWith ( 'Key' ) ) ) {
153+ barcode += e . shiftKey
154+ ? latinKeyCodes [ e . code ] ?. [ 1 ] ?? e . code . charAt ( 3 )
155+ : latinKeyCodes [ e . code ] ?. [ 0 ] ?? e . code . charAt ( 3 ) . toLowerCase ( )
129156 } else {
130157 barcode += e . key
131158 }
Original file line number Diff line number Diff line change 11{
22 "name" : " barcode-hid-reader" ,
3- "version" : " 1.0.2 " ,
3+ "version" : " 1.0.3 " ,
44 "description" : " simple js lib for capturing data from HID barcode scanners" ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments