Answer the question
In order to leave comments, you need to log in
How to get non-printable character via web form?
The bottom line is this: there is a web form on ASP.Net WebForms, where there is a TextBox into which the client needs to scan a barcode (GS1 Databar).
According to the specification, the barcode contains the FNC1 (0x1D) ASCII Group Separator character (non-printable).
The problem is that the scanner imitates keystrokes when scanning. That is, this character is encoded as clamped CTRL + 0xDD. Accordingly, this character does not fall into the text box and is not displayed in any way. Well, as a result, only printed characters are transmitted to the server.
The problem is on the client side, with JS I am very mediocre, I made such a script:
<script type="text/javascript">
var ctrlReceived = false;
function handleStroke(event) {
var ctl = document.getElementById('hfTargetControl').value;
if (ctrlReceived && event.keyCode == 221)
document.getElementById(ctl).value += '|';
ctrlReceived = (event.keyCode == 17);
return null;
};
</script>
<input name="ctl00$ContentPlaceHolder1$ctl02$txtScanBoxBarcode"
type="text"
id="txtScanBoxBarcode"
class="TextField"
onkeydown="handleStroke(event);"
style="width:60%;" />
Answer the question
In order to leave comments, you need to log in
Yes, you can sniff codes on the js side and transfer them to the server as is, for example, separated by commas, parse them on the server. Or convert to another encoding, as an option:
<script>
var inputKeys = [];
function handleStroke(event) {
inputKeys.push(event.keyCode);
onSubmitForm();
};
function onSubmitForm(){
console.log('Через , =' + inputKeys.join(','));
// если надо пееркодировать, закодировать https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder
var utf8decoder = new TextDecoder('utf8');
console.log('Пример, в utf8 =' + utf8decoder.decode(new Uint8Array(inputKeys)));
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question