Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
How to capture barcode hex code keystrokes in an input tag

I have a Datalogic Memor10 barcode scanner which looks and acts a lot like an Android phone, except that additionally it has a barcode scanner in the front. The barcode scanner can be triggered by pressing a key on the side of the Memor10. It also has a feature it calls a Keyboard Wedge which is luckily enabled by default, since I was unable to figure out how to get its complicated settings to be changed. The Keyboard Wedge apparently causes any scanned barcode to also be typed as keystrokes; so that, for example, when you have an input tag on a web application it will type the barcode into that input as keystrokes.

This works great for simple barcodes, however the barcode I would like to scan is an South African drivers license barcode which is encrypted with RSA encryption and therefore the keystrokes returned could be any byte character. This is a problem, since keystrokes such as Tab and Enter would leave the input field or submit by default.

The included form tag is only to prevent Oracle Apex's native form submission.

I have tried unsuccessfully to prevent this and just get the byte codes as hex characters with a simple input screen in Oracle Apex. My Javascript/jQuery/HTML code is currently the following:

Static content region:

<form method="POST" action="javascript:void(0);">
   <input type="text" id="barcode" name="barcode">
</form>

On page load:

/*
$("#barcode").on('keyup', function(e) {
    console.log(e.keyCode.toString(16));
    e.preventDefault();
});
*/
$("#barcode").keypress(function(event) {
   console.log(event.which.toString(16));
   event.preventDefault();
});

However this does not work well, since Tab still leaves the input field and Enter works the first time and then stops working, only to start working again if you press another key inbetween. Not sure which other byte codes would cause issues. What code can I use to successfully capture the long string of byte codes sent as keystrokes to the input tag by the Memor10 barcode scanner? Or is there some other way of achieving this? I would like this to be a web application and not an Android native app.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The keypress event is fired when a character value is pressed down. Also, it is deprecated. You should use the keydown event, which is fired for all keys.

<form method="POST" action="javascript:void(0);">
  <input type="text" id="barcode" name="barcode">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
  
/*$("#barcode").on('keyup', function(e) {
    console.log(e.keyCode.toString(16));
    e.preventDefault();
});*/

$("#barcode").on('keydown',function(event) {
   console.log(event.which.toString(16));
   event.preventDefault();
});
</script>

This first snippet will help you prevent the tab character from causing damage.

Next, to see if there are issues with other key codes, I wrote a script which will fire an event for all key codes from 0 to 256.

$("#barcode").on('keydown',function(event) {
   console.log(event.keyCode.toString(16));
   event.preventDefault();
});

const el = document.getElementById('barcode')
for (let i = 0; i < 256; ++i) {
  el.dispatchEvent(new KeyboardEvent('keydown',{'keyCode':i}));
}
<form method="POST" action="javascript:void(0);">
  <input type="text" id="barcode" name="barcode">
</form>
<script
  src="https://code.jquery.com/jquery-3.6.0.slim.min.js"
  integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI="
  crossorigin="anonymous"></script>

It seems to work. Now you can gather all key strokes in an array to recompose your bar code.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda