iOS:如何检测硬件蓝牙键盘上的转义/控制键? [英] iOS: How to detect the escape/control keys on a hardware bluetooth keyboard?

查看:499
本文介绍了iOS:如何检测硬件蓝牙键盘上的转义/控制键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚如何检测到连接到iOS设备的蓝牙键盘上的Escape(以及其他键组合,如Ctrl和alt)。

I'm trying to figure out how to detect that the Escape (and other key combinations like Ctrl and alt) have been pressed on a bluetooth keyboard attached to an iOS device.

有些答案似乎表明这是不可能的。然而,Appstore中有应用程序执行此操作(例如iSSH),因此我假设可能以某种方式使用公共API。

Some answers seem to suggest this isn't possible. However there are apps in the Appstore that do this (for example iSSH) so I assume it is possible using the public APIs somehow.

我尝试创建自己的UITextInput但是按下Escape键时没有任何结果。我可以看到iPad可能响应的唯一部分是VoiceOver启用时(Escape在Safari中的作用),所以我想知道是否有通过辅助功能API的方法?

I've tried creating my own UITextInput however this receives nothing when the Escape key is pressed. The only part of the API I can see where the iPad might respond is when VoiceOver is enabled (Escape works as back in Safari), so I'm wondering if there's a way in via the accessibility API?

我还试图看看我能从NSNotificationCenter中观察到的东西是否有帮助,但还没有找到任何东西。

I've also tried to see if there's something I can observe from NSNotificationCenter that might help, but have yet to find anything.

欢迎提出建议,我已经在这一天闯入这一天了,现在我有点亏。

Suggestions welcome, I've been hacking away at this for a day and I'm at a bit of a loss now.

推荐答案

您现在可以在iOS 7中执行此操作。例如,要实现转义键,请覆盖UITextView并在您的类中放置以下方法:

You can do this now in iOS 7. For example, to implement the escape key, override UITextView and place the following methods in your class:

- (NSArray *) keyCommands {
    UIKeyCommand *esc = [UIKeyCommand keyCommandWithInput: UIKeyInputEscape modifierFlags: 0 action: @selector(esc:)];
    return [[NSArray alloc] initWithObjects: esc, nil];
}

- (void) esc: (UIKeyCommand *) keyCommand {
    // Your custom code goes here.
}

您无需检查以确定您使用的是iOS 7,因为早期版本的操作系统不会调用keyCommands方法。

You don't need to check to be sure you are on iOS 7, since earlier versions of the OS won't call the keyCommands method.

这篇关于iOS:如何检测硬件蓝牙键盘上的转义/控制键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆