4

Our reception has a barcode scanner plugged into a Macbook Mini, which is used by the receptionist. When people 'check in', they use the barcode scanner to scan their membership card, which then writes to a browser window.

If the receptionist has something else open, and therefore the relevant browser window is not the focus, then the input gets ignored.

So far, I have figured out that the input looks to OSX like a keyboard. My plan is to intercept the input from that 'keyboard' and use AppleScript to always send it to the same browser window.

I realise the whole thing can be improved - use a dedicated micro-device that just makes a CURL request using an API. However, for the moment, there is no API, no micro-device, and I need a solution ASAP.

So how do I intercept input from a specific keyboard? Or is there another quick solution?

Dan Blows
  • 20,846
  • 10
  • 65
  • 96

2 Answers2

4

I had to do something similar, on windows though. In my case the browser window usually was not open and I had to open it and browse somewhere specific with the barcode data.

I discovered that many barcode scanners can emulate a serial port even though they have a USB connection, including the one I had.

In most programming languages serial port data is very easy to read so the solution that I went with was a Java windows service that receives serial port scans and opens the appropriate URL when scanned. I posted some of the bare bones scan reader code here some time ago.

Anyway, you could see if your model can emulate serial port data and then you can capture it for your purposes, I think it would be better than a keyboard hook.

Community
  • 1
  • 1
egerardus
  • 11,316
  • 12
  • 80
  • 123
1

The modern approach to your problem is to configure the barcode scanner to use the so-called HID POS or USB OEM mode. In that mode, the scanner remains connected to the computer directly via USB but it won't send keyboard presses any more but rather codes similar to what you get with the serial port mode.

The USB HID specificaton does define the codes for barcode scanners, and some scanners, like the ones made by GoDEX, follow this protocol. You'll have to implement some USB specific code in your OS X app for this, using the IOKit API for user space handling. But I found it not too difficult to accomplish.

However, some scanners, like those made by Datalogic, do not use the official HID protocol for scanners. Instead, they use a private protocol that's not publically documented. With some reverse engineering and digging I figured out that protocol as well, though.

See my question "Enable USB-OEM (HID POS) mode in a Datalogic barcode scanner" for details on that.

But if you don't want to go down this route of writing your own USB handlers, you can always just get a common Serial-to-USB adapter and install a matching serial driver on your Mac, and then use the scanner in serial mode. When getting a serial adapter, there are two general types: One uses a Prolific chipset, the other an FTDI chipset. The Prolific ones are badly supported by the manufacturer - their drivers are outdated and do not even support the full range of control lines (CTS, RTS etc.). However, there's an independent driver that I can recommend: https://www.mac-usb-serial.com - it's not free but it's well supported and I can confirm that it's working reliably with a Datalogic barcode scanner over the serial port and connected to a Mac via a Prolific-based adapter.

Community
  • 1
  • 1
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149