kIOHIDOptionsTypeSeizeDevice causes device to become unresponsive
Question
I'm trying to write a simple command line program which sends keystrokes on a given keyboard to a UDP server. I'm programming on OSX using the IOKit
framework and its IOHIDManager
class.
For the purpose of my program, I'd like to use the kIOHIDOptionsTypeSeizeDevice
when opening the IOHIDManager
instance and sending the UDP messages in the callback setup using IOHIDManagerRegisterInputValueCallback
.
When I setup the filtering through the IOHIDManagerSetDeviceMatching
function to match the internal keyboard of my MacBook Pro, everything works fine: key presses aren't passed on to the focused application anymore and events correctly sent over UDP.
When I try to match a USB CardReader ( http://www.gitak.com/GIT-200USB.PDF ), everything works correctly up to the first event sent by the device when swiping a card. After the first character, the registered callback isn't called anymore.
To be more precise:
- Device is correctly matched (even if unplugged multiple times)
- First received character is correctly handled
- The device has a LED to indicate when it's ready for a new swipe, normally after a swipe it turns back green, but in this case, after the first event is sent, it remains off
- Everything works as expected when using the internal keyboard with
kIOHIDOptionsTypeSeizeDevice
- Everything works as expected when using the card reader with
kIOHIDOptionsTypeNone
instead ofkIOHIDOptionsTypeSeizeDevice
(even though the events are still passed to the focused application) - After becoming unresponsive, unplugging and replugging the device repeats the described behavior
- The program was run with root privileges
The relatively simple program can be found here:
https://gist.github.com/3783042
How can I modify it in order to not cause the card reader to become unresponsive after having sent the first event?
La solution
As it turns out, it was the device being defective. I ordered a new one and everything works now!