如何使用媒体键读取USB键盘的键代码

Seb*_*oth 5 iphone ipad ios

是否可以使用特殊的iOS API或通用TextInput字段读取非标准键的键代码?我有一个带有特殊按钮的多媒体键盘,可让我的iPad应用程序了解这些密钥代码.

我知道iOS已经可以使用其中一些(即音量增大/减小,下一首/上一首曲目).

sku*_*kue 1

您可能想尝试子类化 UIApplication 并覆盖sendEvent:以查看哪些事件通过那里。鉴于 UIEvent 没有记录 iOS 上的键盘事件支持(与 AppKit 中的 NSEvent 不同),我怀疑您是否会看到键盘事件......但值得一试。我没有 BT 键盘,无法自己尝试。

要使用 UIApplication 子类,请编辑main.m子类并将其作为第三个参数传递给 UIApplicationMain:

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

这种策略在桌面 Cocoa 应用程序中并不罕见,这里也有解释:

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