Overriding sendEvent in custom UIApplication to detect hardware keyboard event

I am developing an iPad application that needs to read data from a hardware keyboard. The main user will be touching the screen normally, while the other user will control some aspects of the app from the adjacent Bluetooth keyboard that is paired with the iPad.

Overriding the keyCommands property in UIResponder works fine so far. But when we moved the application to Cocos2d (which uses its own responder chain) all keyCommands stopped working.

I tried to subclass UIApplication with the overridden sendEvent: method , something simple:

#import "MyUIApplication.h"

@implementation MyUIApplication  // subclass of UIApplication

-(void)sendEvent:(UIEvent *)event {
    [super sendEvent:event];
    NSLog(@"Event detected");


As far as I can tell, this successfully detects all events except hardware keyboard events, which seem to be completely ignored. Is there a way to detect these events without using keyCommands and UIKeyCommand s?


source to share

All Articles