Adopting UIKeyInput protocol to get input from a Bluetooth keyboard

后端 未结 3 2171
慢半拍i
慢半拍i 2021-02-15 14:01

I have a Bluetooth foot switch that\'s basically a wireless keyboard. One pedal sends the up arrow key, the other sends the down arrow key. I want to be able to execute my own

3条回答
  •  甜味超标
    2021-02-15 14:26

    in IOS 7 it is easy. In previous versions - not official. Can be removed from App Store.

    -(NSArray * ) keyCommands {
        if ([[[UIDevice currentDevice] systemVersion] intValue] <7) return nil;
        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 *escapeCom = [UIKeyCommand keyCommandWithInput:UIKeyInputEscape modifierFlags:0 action:@selector(escapeChar:)];
        return [[NSArray alloc] initWithObjects: upArrow, downArrow, leftArrow, rightArrow, escapeCom, nil];
    }
    

    It works for me, hope will be useful for you. Added version check to avoid usage in non-iOS7 devices.

提交回复
热议问题