Jiri Zaloudek
Jiri Zaloudek

Reputation: 380

QT HID Barcode reader different keystrokes inside textinput then Keys.onPressed

So in summary, I have a barcode reader MC3300 (not relevant) where I have my barcode reading app, and some characters it reads not as they are inside the barcode, its these:

However the common characters like alphabetical or numbers it reads properly.

But, when I open any notepad on the device and scan it, then export to txt and walk through each character, then it reads properly... therefore it must be some setting in my app...

can I ask for little clartification, perhaps example how should I implement?

Thank you

EDIT: I have this DMC:

"[)>06V00000596323S00000407141TIA1315JV2P634-00650-0020PQ100014Z16Z12D230903"

which are there in ASCII:

94 41 62 30 48 54 29 86 48 48 48 48 48 53 57 54 51 50 29 51 83 48 48 48 48 48 52 48 55 49 52 29 49 84 73 65 49 51 49 53 74 86 50 29 80 54 51 52 45 48 48 54 53 48 45 48 48 29 50 48 80 29 81 49 48 48 48 29 49 52 90 29 49 54 90 49 29 49 50 68 50 51 48 57 48 51 30 4

and these ASCII are output from:

TextField {
    onTextChanged: {
         console.log(text.charAt(text.length - 1)+ " ("+text.charCodeAt(text.length - 1)+"))
    }
}

however, if I use it like this:

property string scannedValue: ""
Item {
    focus: true
    Keys.onPressed: { scannedValue += String.fromCharCode(event.key); }
}
onScannedValueChanged: {
    console.log(scannedValue .charAt(scannedValue.length - 1)+ " ("+scannedValue .charCodeAt(scannedValue.length - 1)+"))
}

i have very different result... which would be:

"[)>06V00000596323S00000407141TIA1315JV2P634-00650-0020PQ100014Z16Z12D230903 Q100014 Z16 Z112 D230903"

and in ASCII:

91 32 48 32 46 65535 48 54 65535 32 86 48 48 48 48 48 53 57 54 51 50 65535 51 32 83 48 48 48 48 48 52 48 55 49 52 65535 49 32 84 32 73 32 65 49 51 49 53 32 74 32 86 50 65535 32 4 54 51 52 45 48 48 54 53 48 45 48 48 65535 50 48 32 4 65535 32 81 49 48 48 48 65535 49 52 32 90 65535 49 54 32 90 49 65535 49 50 32 68 50 51 48 57 48 51 65535 65535

therefore, where these differences are coming from and mainly how do I remove them so i will get the result same as when I scan it right inside the TextField?

Upvotes: 0

Views: 285

Answers (1)

David K. Hess
David K. Hess

Reputation: 17246

Don't use event.key - that's a keyboard code and not an ASCII value. Try using event.text instead.

More info here:

https://doc.qt.io/qt-5/qml-qtquick-keyevent.html#text-prop

Upvotes: 1

Related Questions