简体   繁体   中英

How to enable pasting with keyboard shortcut into SwiftUI macOS agent application

I'm creating an app with Swift 5 and SwiftUI. The application runs as a status bar app (LSUIElement is true). I've created a simple preferences window with SwiftUI with a couple of TextField .

However, I don't know how I can enable pasting into those fields with Cmd+V. The app being an agent, it's never really activated so even with the preferences window focused, app's menu bar doesn't show up (on the left-hand side of the status bar).

This is how I create the window:

let hostingController = NSHostingController(rootView: PreferencesView())
preferencesWindow = NSWindow(contentViewController: hostingController)
preferencesWindow!.center()
preferencesWindow!.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)

When trying to paste using Cmd+VI hear the macOS's "forbidden" chime. Right-clicking the field allows me to select Paste from the popup menu.

I have the same trouble, then I find these shortcuts is provided by the 'Edit' menu item. so you can try restoring the default menu in Main.storyboard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM