[英]How do I save the focus context and return to it in an OSX application?
I'm writing a menubar application that shows a window when a global hotkey is pressed. 我正在编写一个菜单栏应用程序,当按下全局热键时该应用程序显示一个窗口。 The application has no dock icon and no normal menu (just the statusItem).
该应用程序没有停靠图标,也没有常规菜单(仅statusItem)。
Prior to activating the application, lets say I have a text box on a webpage in chrome focused. 在激活该应用程序之前,可以说我在chrome网页上有一个文本框。 How can I refocus that text box when my application is dismissed.
当我的申请被驳回时,如何重新定位该文本框。
If you're familiar with Text Expander, they do something similar. 如果您熟悉Text Expander,它们会执行类似的操作。
I figured this out. 我想通了。 You need an NSRunningApplication:
您需要一个NSRunningApplication:
@implementation AppDelegate { NSRunningApplication *_previousApplication; }
Then store the previous application before you become active: 然后在激活之前存储先前的应用程序:
_previousApplication = [[NSWorkspace sharedWorkspace] frontmostApplication];
Finally, after you deactivate, just bring back the other application: 最后,停用后,只需重新启动另一个应用程序即可:
[_previousApplication activateWithOptions:NSApplicationActivateIgnoringOtherApps];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.