Keyboard shortcuts iPad cannot be used until screen is pressed.

Hello I have this issue where I have "shortcut keys" that I have added to a ViewController. When navigated to the ViewController I cannot use the "shortcut keys" right away. I first need to "press" anywhere on the screen to be able to use the shortcut.

I use this code:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIKeyCommand* commandA = [UIKeyCommand keyCommandWithInput:@"a" modifierFlags:UIKeyModifierCommand action:@selector(handleCommand:)];

    [self addKeyCommand:commandA];    
}

- (void)handleCommand:(UIKeyCommand *)keyCommand {
    // Hangup call.
    [self btnIncomingAnswerPressed:NULL];
}

I am not sure why this happens, but I it would be really good if a user could use a shortcut key as soon as they navigate to the ViewControllor, instead of first have to press anywhere on the app.

would you try this modified code and see if this work without needing " press" anywhere on the screen

  • (void)viewDidLoad { [super viewDidLoad];

    // Create and add the key command UIKeyCommand* commandA = [UIKeyCommand keyCommandWithInput:@"a" modifierFlags:UIKeyModifierCommand action:@selector(handleCommand:)]; [self addKeyCommand:commandA];

    // Make the view controller the first responder [self becomeFirstResponder];

}

  • (BOOL)canBecomeFirstResponder { return YES;

}

  • (void)handleCommand:(UIKeyCommand *)keyCommand { // Hang up call [self btnIncomingAnswerPressed:NULL];

}

Keyboard shortcuts iPad cannot be used until screen is pressed.
 
 
Q