3

Question

I would like to catch/preview all keyboard inputs that our application receives.

It would be enough if only the inputs from the external keyboard is caught.

I've come around solutions examples such as register a notification observer for UITextViewTextDidChangeNotification and UITextFieldTextDidChangeNotification but since this requires a TextView or TextField to be the current first responder it does not capture all our needs.

An example for this is that we are using the scanning to filter a list where the entire view is the list and navigation buttons.

Are there any way to register an observer that can preview all key inputs the application recieves?

Background:

I have an iPhone application that scans barcodes to identify objects at several different views.

Currently we scan the barcodes either by the camera (using zbar library) or with an MFI-certified barcode scanner. In order to support more devices (for example an iPad) we are investigating other means to capture bar codes.

One of the device classes we are looking at are bluetooth scanners that identifies as a HID keyboard. This would be a great addition since it be usable with different products and manufactures.

In order to

nj.
  • 756
  • 1
  • 5
  • 21
  • You have to use private API. see http://stackoverflow.com/questions/15629514/iohideventsystemclientschedulewithrunloop-with-exc-bad-access – storoj Oct 10 '13 at 09:11
  • @storoj Thanks! Even if that is quite of a bummer :) If you have any good references to why it can't be done without private APIs you can post them as an answer and I'll mark it as the answer. – nj. Oct 10 '13 at 09:21

2 Answers2

2

Another option for iOS 7 and above is to use declare a keyCommands method on the current view controller. It can trap special key combinations. The downside is that you'll need to explicitly declare what you're looking for.

I answered my own question over here about getting special characters out of 2D barcodes from scanners connected in HID mode.

Community
  • 1
  • 1
sfaxon
  • 551
  • 6
  • 10
1

Seems like usage of IOHID** functions may not be rejected by AppStore reviewers because IOKit is "white-list-framework" (Will Apple reject Mac OS App which uses IOKit framework?)

So you can really try to use callback function from this topic IOHIDEventSystemClientScheduleWithRunLoop with EXC_BAD_ACCESS, hope that helps! I used this code and it works even if your app is in background (just set special background mode), captures all system touch and keyboard events.

Community
  • 1
  • 1
storoj
  • 1,851
  • 2
  • 18
  • 25
  • Looks like the way to go. I haven't confirmed that it works yet but it looks to be the right way. Thanks! – nj. Oct 14 '13 at 08:22