Cocoa NSStatusBar Global HotKey [英] Cocoa NSStatusBar Global HotKey

查看:177
本文介绍了Cocoa NSStatusBar Global HotKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个位于系统状态栏中的NSStatusBar可可应用程序。

I have created an NSStatusBar cocoa application which sits in the system status bar.

我想分配一个热键,以便在按下时切换我的应用程序,

I want to assign a hotkey so that when pressed it toggles my applications and show the menu.

这是可能吗?在我的搜索和试验中,我发现了几种不同的方式来分配全局热键,当应用程序在后台但我找不到任何有问题的菜单显示的方式。

Is this possible?, In my searching and experimenting I have found a few different ways of assigning global hot keys that can be pressed when your application is in the background but I can't find any way to problematically make the menu show.

这可能吗?如果有人认为分配全局热键的方法是最好的,请张贴

Is this possible?, If anyone thinks a way of assigning a global hotkey is best please post it.

感谢。

其中一个热键教程找到了 http://dbachrach.com/

One of the hotkey tutorials I found was on http://dbachrach.com/blog/2005/11/program-global-hotkeys-in-cocoa-easily/ for anyone interested.

推荐答案

实际的热键API ,它仍然存在于Snow Leopard中,并且提供64位。它是专门为此目的而设计的,与NSEvent方法不同,NSEvent方法本质上只是一个基于CGEventTaps的基于块的包装器。

There is an actual hotkey API, which still exists in Snow Leopard and is available in 64-bit. It's designed specifically for this purpose, unlike the NSEvent methods, which are essentially just a block-based wrapper around CGEventTaps.

不同的是NSEvent方法(或CGEventTaps )让你看看每个事件,而热键API只有当用户按 热键时才调用你的函数。

The difference is that the NSEvent methods (or CGEventTaps directly) make you look at every event that comes in, whereas the hotkey API only calls your function when the user presses your hotkey.

这篇关于Cocoa NSStatusBar Global HotKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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