LDK
LDK

Reputation: 2575

iOS responding to physical keyboard events and UIInternalEvent

I want to be able to detect physical keyboard (e.g. bluetooth) events in an iOS app.

I came across this post: iOS: how to respond to up/down/left/right arrow event from physical keyboard? which suggests over riding UIApplication:sendEvent .

After over riding UIApplication, I can tell that keypresses are "UIInternalEvent" and do not fit into one of the 3 documented event types. Using the debugger I'm unable to differentiate when a user clicks "a" from when they click "left arrow". Any suggestions?

my code:

- (void)sendEvent:(UIEvent *)event{
  UIEventType u = [event type];

  if(u != UIEventTypeTouches){

  }
  [super sendEvent:event];
}

The debugger break point is within the if statement.

EDIT: apparently UIInternalEvent is a wrapper for GSEvent. GSEvent info can be found here: https://github.com/kennytm/iphone-private-frameworks/blob/master/GraphicsServices/GSEvent.h but I still don't know how to make use of it.

Upvotes: 1

Views: 4657

Answers (1)

Jorge Aguirre
Jorge Aguirre

Reputation: 2857

Using the private framework GraphicsServices, you can get the GSEventRecord using the UIEvent object in the sendEvent of the UIApplication. More less like this:

GSEventRef e = [UIEventObject _gsEvent];
const GSEventRecord *record = GSEventGetGSEventRecord(e);

Then try looking at the flag value of the record structure, it changes when you press shift, control, etc.

Upvotes: 1

Related Questions