如何以编程方式使可可应用程序活跃 [英] How to programmatically make cocoa application active

查看:101
本文介绍了如何以编程方式使可可应用程序活跃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

...窗口显示精细&在其他窗口的前面(如我想要的),然而直到我手动点击窗口时,任何应用程序是活动的,当窗口显示保持活动。我期待的makeKeyAndOrderFront使应用程序也是活动的,但是添加一个NSLog行到我的-applicationWillBecomeActive显示它没有得到任何活动通知,直到鼠标点击执行。

... 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.

有没有人知道我如何设置我的应用程序active @同时发出-makeKeyAndOrderFront?我需要它活跃,以便它可以开始接受键盘输入 - 任何需要帮助: - )

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 :-)

推荐答案

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

这篇关于如何以编程方式使可可应用程序活跃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆