Usage scenarios

Support external keyboards for your apps, iOS apps or iPad apps. One might ask, why would an iOS app support an external keyboard? M1 is the answer 😊

How to use

- (BOOL)canBecomeFirstResponder {
    return YES;
}
- (NSArray<UIKeyCommand* >*)keyCommands{
    UIKeyCommand *command = [UIKeyCommand commandWithTitle:@"shift+e" image:nil action:@selector(eShiftKeyPressed) input:@"e" modifierFlags:UIKeyModifierShift propertyList:nil];
    return @[command];
}

- (void)eShiftKeyPressed{
    NSLog(@"%s ==",__func__);
}
Copy the code

Pay attention to the point

KeyCommands is a method of UIResponder, which means that the class you’re overriding must be on the chain of event response, so if it’s not triggered, try becomeFirstResponder

Simulator test

You need to set two places for the simulator to receive your keyboard input

The last point

Once it’s plugged in and set up correctly, and the emulator is at the front of the screen, hold down Command to see a list of shortcuts you just set.

Shortcut key list Call conditions:

  • Only the iPad app can exhale
  • Too few Settings will display, too many will not display