简体   繁体   English

如何保存焦点上下文并在OSX应用程序中返回焦点上下文?

[英]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.

相关问题 OSX-使用controlTextDidEndEditing:notification后,如何获得焦点 - OSX - After using controlTextDidEndEditing:notification , how do I get focus 如何从osx应用程序播放系统声音? - How do I play the system sound from an osx application? 如何将我的OSX Cocoa应用程序与Facebook连接? - How do I connect my OSX Cocoa Application with facebook? OSX终端 - 更改应用程序焦点 - OSX Terminal - Change Application Focus 如何将焦点转移到Cocoa中的先前应用程序? - How do I cede focus to the previous application in Cocoa? 如何在应用程序集中时捕获键盘/鼠标事件? - How do I Capture keyboard/mouse events with my application in focus? 如何在OSX上保存iMessage对话? - How can i save iMessage conversations on OSX? 如何捕获OSX的所有正在运行的进程列表并将它们保存为Xcode / Cocoa中的文件? - How do I capture a list of all running processes for OSX and save them as a file in Xcode / Cocoa? wkhtmltopdf在OSX上打开一个应用程序,直到我专注于此应用程序后,它才完成工作 - wkhtmltopdf opens an application on OSX and doesn't finish its job till I focus this application 如何在OSX的C ++应用程序中正确使用文件I / O路径? - How do I use File I/O pathing correctly in C++ application in OSX?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM