Safari MacOS 14 Sonoma Consumes Global Key Events + Does Not Yield Activation

Context

I am developing a small tool which is a small terminal to perform AI prompts which you should be able to quickly invoke upon a key press (https://swiftprompt.ai).

This is how I try to bring up the application and obtain focus.

if #available(macOS 14.0, *) {  
    NSApplication.shared.activate()
} else {
    NSApplication.shared.activate(ignoringOtherApps: true)
}

promptWindow.makeKeyAndOrderFront(self)

I also use `NSEvent.addGlobalMonitorForEvents(..) to support specific shortcuts to trigger certain functionality.

The Problem

Since MacOS 14, I noticed sometimes issues with activating and obtaining focus for the window. Also shortcuts using letter keys are not recognized. I noticed when Safari is running while my application is launching, it will not be able to get global key events nor retain focus when Safari is active. As soon as Safari is closed everything works. Also if Safari is not running while launching my application everything works perfectly, even if Safari is opened after launching my application.

This is a problem for me, as users of my application should be able to do one keypress and start writing without having to additionally having to click on the window to focus it. I expect many users having Safari open and running.

I tried other shortcut libraries like (HotKey) for which I am getting the same issues. Is anyone running into similar issues or can reproduce this problem? I would appreciate any help.

Cheers, Mo

Safari MacOS 14 Sonoma Consumes Global Key Events + Does Not Yield Activation
 
 
Q