如何以编程方式使可可应用程序处于活动状态
我有一个后台进程,当按下热键时,会出现一个透明窗口:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看
[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
。Look at
[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
.对于 10.6 或更高
For 10.6 or greater
@Arvin 答案的 Swift 4.2+
Swift 4.2+ of @Arvin answer