Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird characters when dealing with hyphen #19

Open
Greensahil opened this issue Aug 30, 2020 · 5 comments
Open

Weird characters when dealing with hyphen #19

Greensahil opened this issue Aug 30, 2020 · 5 comments

Comments

@Greensahil
Copy link

I have a barcode that I printed with Dymo label maker that translates to QC-157. But when I tried to scan it in your playground I get:

[onScan]: Code: �QC½157 Quantity: 1

@Greensahil
Copy link
Author

image

If I activate the OnKeyDetect you can see that it is clearly reading some characters wrong. For example it is reading 16 as the first character and there is no ASCII equivalent of 16

It is also reading ASCII 189 for the symbol - which is not true.

My scanner is working just fine because if I open a notepad and try to scan the same code I get:

QC-157

@kabachello
Copy link
Collaborator

kabachello commented Sep 4, 2020

Hi! Use the keyCodeMapper callback to map the key codes to the desired characters. See example here: https://github.com/axenox/onscan.js#decoding-key-codes.

The trouble is, that the key codes from the JavaScript events depend on a lot of things: the hardware, the operating system, the virtual keyboard used, the keyboard layout, etc. I found, that it practically impossible to decode all codes reliably. Using a custom key code mapper, that deals with the issues of your specific hardware is much easier!

You can also check "keyCodeMapper" in the playground to see how the default mapper works.

@Emsal92
Copy link

Emsal92 commented Jan 22, 2021

This worked really well for me
keyCodeMapper: function(e) { return e.key || String.fromCharCode(e.keyCode); },

@Rragen
Copy link

Rragen commented Aug 23, 2021

Because 16 is the code of the shift key, with the @Emsal92 code I have a weid result with the word "Shift" between each character in the result string. It's the way it recreates an uppercase code ( does lowercase code even exist ? ), for example for the code /123 I had Shift/Shift1Shift2Shift3.

by simply exclude 16 in the keyCodeMapper callback, I have a good result.
keyCodeMapper: (e) => ((e.keyCode === 16) ? '' : e.key || String.fromCharCode(e.keyCode)),

Edit
Excluding 16 was not a good idea, because it results in the weird characters ^^
This stack overflow gives some solutions :

@designosis
Copy link

This keyCodeMapper mess makes onscan useless with QR codes.
What a damn shame!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants