Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read key codes of USB Keyboard with Media Keys

Tags:

ios

iphone

ipad

Is it possible to read key codes of non-standard keys using an special iOS API or via the generic TextInput field? I have a multimedia keyboard with special buttons & like to make my iPad app aware of these key codes.

I know iOS can use some of them already (i.e. volume up/down, next/prev track).

like image 990
Sebastian Roth Avatar asked Nov 15 '22 03:11

Sebastian Roth


1 Answers

You might want to try subclassing UIApplication and overriding sendEvent: to see what events pass through there. Given that UIEvent doesn't document keyboard event support on iOS (as opposed to NSEvent in AppKit), I'm skeptical that you'll see keyboard events... but it's worth a try. I don't have a BT keyboard to try it out myself.

To use a UIApplication subclass, edit main.m and pass your subclass as the third argument to UIApplicationMain:

int main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, YourApplicationSubclass, nil);
    [pool release];
    return retVal;
}

This strategy isn't uncommon in desktop Cocoa apps and is also explained here:

http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html

like image 179
skue Avatar answered Dec 28 '22 06:12

skue