Tag: uikeycommand

iOS Swift中断键盘事件

我有问题来拦截键盘事件。 我已将我的iOS与SteelSeries Free(游戏手柄控制器)连接起来,当连接到iOS时将被检测为蓝牙键盘。 这是我打开Notes时testing的,游戏手柄上的任何button都会写一个字母。 我需要拦截这个button,并运行我自己的function,但不幸的是,我无法这样做。 我一直在尝试使用GCController,但显然它不被检测为游戏控制器对象。 当我打印计数,它显示为0.我的代码如下。 let gameControllers = GCController.controllers() as! [GCController] println("configureConnectedGameControllers count: \(gameControllers.count)") 所以我认为这是因为游戏手柄被检测为蓝牙键盘,这就是为什么它不被检测为游戏控制器。 所以我试图改用UIKeyCommand。 以下是我的代码: override func viewDidLoad() { super.viewDidLoad() var keys = [UIKeyCommand]() for digit in "abcdefghijklmnopqrstuvwxyz" { keys.append(UIKeyCommand(input: String(digit), modifierFlags: .Command, action: Selector("keyPressed:"))) keys.append(UIKeyCommand(input: String(digit), modifierFlags: .Control, action: Selector("keyPressed:"))) keys.append(UIKeyCommand(input: String(digit), modifierFlags: nil, action: "pressKey")) } } override func […]

使用UIKeyCommand检测连续按键

可以持续按键吗? 我正在使用keyCommands :拦截在外部键盘上按下的箭头键,但每次按下只能打1个呼叫。 只要按住按键,我就会喜欢每X毫秒接听多个电话,或者当按键被按下时以及释放时接听电话。 这是我的代码: – (NSArray *)keyCommands { UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow modifierFlags:0 action:@selector(upArrow:)]; UIKeyCommand *downArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputDownArrow modifierFlags:0 action:@selector(downArrow:)]; UIKeyCommand *leftArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:0 action:@selector(leftArrow:)]; UIKeyCommand *rightArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:0 action:@selector(rightArrow:)]; UIKeyCommand *leftArrowCmd = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:UIKeyModifierCommand action:@selector(leftArrowCmd:)]; UIKeyCommand *rightArrowCmd = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:UIKeyModifierCommand action:@selector(rightArrowCmd:)]; UIKeyCommand *lCmd = [UIKeyCommand […]

如何使用return / enter键创buildUIKeyCommand?

我想制作一个只使用[return]键的UIKeyCommand 。 到目前为止我已经尝试过: UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)]; input键没有全局常量,就像UIResponder.h上,下,左,右和转义一样: // These are pre-defined constants for use with the input property of UIKeyCommand objects. UIKIT_EXTERN NSString *const UIKeyInputUpArrow NS_AVAILABLE_IOS(7_0); UIKIT_EXTERN NSString *const UIKeyInputDownArrow NS_AVAILABLE_IOS(7_0); UIKIT_EXTERN NSString *const UIKeyInputLeftArrow NS_AVAILABLE_IOS(7_0); UIKIT_EXTERN NSString *const UIKeyInputRightArrow NS_AVAILABLE_IOS(7_0); UIKIT_EXTERN NSString *const UIKeyInputEscape NS_AVAILABLE_IOS(7_0); 还有什么我可以尝试捕获返回/input密钥?