2

I have a macOS NSPopover based tray app which shows a popover with login fields (username and password).

Problem is that user is unable to copy-paste his email or password into text fields. The popover doesn't seem to allow keyboard shortcuts for some reason.

Did anyone have similar issues?

Relevant example available here: https://github.com/mixtly87/NSPopoverTest

mixtly87
  • 1,675
  • 15
  • 32

1 Answers1

2

This isn't the easiest thing to solve and you need to do a few things to get this to work.

1 ) add a MainMenu to your MainMenu.xib file.

Even though the main menu won't display (because you're only doing a NSStatusBar item), you want that main menu because of the command keys in the Edit menu (i.e. something to intercept the cmd-X, cmd-C & cmd-V's). Those command keys will be sent to your text field or your webview, whatever is the first responder.

More info can be seen here.

2 )

I made your textfield the first responder by adding:

- (void)viewDidAppear
{
    [super viewDidAppear];
    [self.textField becomeFirstResponder];
}

to your ViewController.m file.

3 )

You also need to make the window brought up by the Status Item a key window. In your example app, you did have a commented out canBecomeKeyWindow method. I uncommented it out and always return TRUE.

More info can be seen here.

Hope this helps!

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • 1
    Thanks Michael, this was really helpful! In my case though, your solution works even without overriding the `canBecomeKeyWindow` and returning `YES`. – mixtly87 Apr 04 '18 at 07:38