1

I am working on a web based Java application (GWT is used for my UI). I have a warehouse management system.I need to scan the barcodes and show them in a textbox. I am aware that the scanners would send keyboard events. How do I capture these events and populate them in my textbox ? Should the cursor focus be on the textbox while scanning the barcode ?

Can anyone please provide a code snippet of how to capture these events and populate in the textbox ?

Please note that this needs to work across different OS and browsers. This should work for laptops/desktops. It is not for mobile apps.

RS389
  • 43
  • 7
  • You cannot capture keyboard event outside the running java application in pure Java. This is for obvious security reason. You would have to use low level *lib* or *dll* that will depend on the OS. – ortis Sep 26 '14 at 14:44

3 Answers3

0

I would recommend setting cursor focus on the input textbox if scanning barcodes is the default action for that page, you can then use a KeyPressHandler on the textbox to intercept the scanner's control character if its set up to fire off a carriage return line feed (enter key) after each scan.

This may be a place to start looking.

A quick search for an example came up with a good one here

Community
  • 1
  • 1
0

Since you cannot distinguish between scanner and keyboard events, just focus on the textbox and wait for the input. Be sure to set up the scanners so they send TAB afterwards, not ENTER.

Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102
0

Depending on you scanner, it is possible to program it to send a predefined prefix before the actual bar code. For example, the scanner I was working with, a Honeywell Voyager 95X0, can be configured to transmit, for example, a Start of TeXt (ASCII 02H) before each bar code (see page Chapter 8, page 42 of the configuration guide). You could then use that prefix to filter out which KeyPressEvents were coming from the scanner (and then move the input to the text box) and which were from the user.

Setting up a "global" KeyPressHandler (so that the user doesn't have to remember to focus the text box before scanning the bar code) should be trivial - see, for example, this thread. The key point is using Event.addNativePreviewHandler to capture the events before they are fired to their handlers.

Igor Klimer
  • 15,321
  • 3
  • 47
  • 57