如何以编程方式使可可应用程序处于活动状态

发布于 2024-08-15 01:07:47 字数 435 浏览 9 评论 0原文

我有一个后台进程,当按下热键时,会出现一个透明窗口:

[window makeKeyAndOrderFront:nil];
[[content animator] setAlphaValue:1.0]; // alpha was 0.0

...窗口显示良好&在其他窗口前面(正如我想要的那样),但是直到我手动单击该窗口之前,窗口出现时处于活动状态的任何应用程序都保持活动状态。我期望“makeKeyAndOrderFront”也使应用程序处于活动状态,但是向我的 -applicationWillBecomeActive 添加 NSLog 行显示在执行鼠标单击之前它不会收到任何活动通知。

有谁知道如何在发出 -makeKeyAndOrderFront 的同时将我的应用程序设置为活动状态?我需要它处于活动状态,以便它可以开始接受键盘输入 - 需要任何帮助:-)

I've got a background process that makes a transparent window appear when a hotkey is pressed:

[window makeKeyAndOrderFront:nil];
[[content animator] setAlphaValue:1.0]; // alpha was 0.0

... the window shows up fine & in front of the other windows (as I want it to), however until I manually click the window whatever application was active when the window appears remains active. I was expecting the 'makeKeyAndOrderFront' to make the application active as well, however adding a NSLog line to my -applicationWillBecomeActive shows it's not getting any active notification until the mouse click is performed.

Does anyone know how I can set my application active @ the same time I issue the -makeKeyAndOrderFront ? I need it active so that it can begin accepting keyboard input - any assistance needed :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乙白 2024-08-22 01:07:47

查看[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];

Look at [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];.

小嗲 2024-08-22 01:07:47

对于 10.6 或更高

[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];

For 10.6 or greater

[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
橙味迷妹 2024-08-22 01:07:47

@Arvin 答案的 Swift 4.2+

NSRunningApplication.current.activate(options: [.activateIgnoringOtherApps, .activateAllWindows])

Swift 4.2+ of @Arvin answer

NSRunningApplication.current.activate(options: [.activateIgnoringOtherApps, .activateAllWindows])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文