6

Possible Duplicate:
OSX HID Filter for Secondary Keyboard?

I would like to write a Mac OSX Application that captures keyboard events on a second keyboard and consume them before other apps get notified? I don't my app to be notified of a keystroke on the main computer keyboard, just the second one. And I don't want other apps to get the keystroke, I want to consume it. Anyone here know the best way to go about this?

Community
  • 1
  • 1
JayGee
  • 577
  • 6
  • 16
  • @GaretJax Your answer from my other question solved my problem perfectly. Here's the link for the benefit of others here: [link](http://stackoverflow.com/questions/8676135/osx-hid-filter-for-secondary-keyboard) – JayGee Mar 13 '14 at 23:15

1 Answers1

0

You will need IOKit to do this. The code would involve writing a kext and intercepting keyboard events and choosing whether to pass them on to the user space. Writing the entire approach here would be too complex and big but I can suggest a few references.

The code at KeyRemap4MacBook has quite a bit of low level code for device reading and interception.

Here is the custom kext that the author has written: https://github.com/tekezo/KeyRemap4MacBook/tree/master/src/core/kext

I suggest you look into the code to see how he has intercepted the keys, remapped them according to the user configuration and send them to the user space.

Nandeep Mali
  • 4,456
  • 1
  • 25
  • 34
  • 1
    You're mostly right, but as I've found out in the meantime, you can avoid writing a kext and use the userspace HID library alongside with kIOHIDOptionsTypeSeizeDevice to get exclusive access to the selected device – GaretJax Sep 25 '12 at 16:30
  • I do recall trying out the `HID LED test tool` example from Apple Documentation which uses the user space HID Manager (on OSX 10.8) and I have not got it working properly yet. Out of the box, the application just crashes. It seems the example was built for Leopard and hasn't been updated since. I haven't located any latest examples yet. – Nandeep Mali Sep 26 '12 at 09:59