本文主要是介绍实现gnome桌面的全局热键,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
gtk+-2.0 没有提供全局热键的功能,而需要使用GConf和 metacity才能得到该功能。
不过有个叫 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> 的人写了一个
libgtkhotkey ,可以提供该功能,而且是跨平台的。
在Fedora系统上,安装libgtkhotkey
$ su
# yum install libgtkhotkey-devel
基本用法
#include <gtkhotkey.h>
链接参数: `pkg-config --cflags --libs gtkhotkey-1.0`
使用方法(编程):
1、注册hotkey:
// used to register the hotkey
static void register_hotkey() {
GtkHotkeyInfo *hotkey_info = gtk_hotkey_info_new("gtkxrandr", "projecter", "<Super>F3", NULL);
if ( hotkey_info == NULL ) {
printf("error 1\n");
}
if ( FALSE == gtk_hotkey_info_bind(hotkey_info, NULL) ) {
printf("[error] can not bind hotkey\n");
}
else {
g_signal_connect(hotkey_info, "activated", G_CALLBACK(hotkey_handler), NULL );
}
}
2、在gtk中捕捉 actived 信号:
// called when the user pressed the combination key.
static void hotkey_handler(GtkHotkeyInfo* hotkey, guint event_time, gpointer user_data) {
// add your code here
}
3.在初始化的时候调用 register_hotkey
int main ( int argc, char* argv[]) {
//...
register_hotkey();
//...
}
这篇关于实现gnome桌面的全局热键的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!