如何在GTK应用程序中拦截系统按键

如何在GTK应用程序中拦截系统按键,gtk,vala,Gtk,Vala,我正在开发一个默认启动最小化的Vala GTK应用程序,我想绑定一个特定的关键字快捷方式,将最小化窗口带到最前面 当应用程序被聚焦时,我能够使用加速器处理键盘事件,但当应用程序被最小化时,我无法截获任何来自系统的按键 如何使应用程序监听系统键盘事件,以便检测相应的按键 谢谢。我查看了的源代码,以了解它如何将Super-e注册为热键。看起来基本上如下所示,包括首先检查是否尚未为应用程序注册自定义热键 // These constants are set at class level. public

我正在开发一个默认启动最小化的Vala GTK应用程序,我想绑定一个特定的关键字快捷方式,将最小化窗口带到最前面

当应用程序被聚焦时,我能够使用加速器处理键盘事件,但当应用程序被最小化时,我无法截获任何来自系统的按键

如何使应用程序监听系统键盘事件,以便检测相应的按键


谢谢。

我查看了的源代码,以了解它如何将
Super-e
注册为热键。看起来基本上如下所示,包括首先检查是否尚未为应用程序注册自定义热键

// These constants are set at class level.
public const string SHORTCUT = "<Super>e";
public const string ID = "com.github.cassidyjames.ideogram";

// Set shortcut within activate method.
CustomShortcutSettings.init ();
bool has_shortcut = false;
foreach (var shortcut in CustomShortcutSettings.list_custom_shortcuts ()) {
    if (shortcut.command == ID) {
        has_shortcut = true;
            return;
    }
}
if (!has_shortcut) {
    var shortcut = CustomShortcutSettings.create_shortcut ();
    if (shortcut != null) {
        CustomShortcutSettings.edit_shortcut (shortcut, SHORTCUT);
        CustomShortcutSettings.edit_command (shortcut, ID);
    }
}
//这些常量是在类级别设置的。
公共常量字符串快捷方式=“e”;
public const string ID=“com.github.cassidyjames.ideogram”;
//在激活方法中设置快捷方式。
CustomShortcutSettings.init();
bool has_shortcut=false;
foreach(CustomShortcutSettings.list\u custom\u shortcuts()中的var快捷方式){
if(shortcut.command==ID){
has_shortcut=true;
返回;
}
}
如果(!有_快捷方式){
var shortcut=CustomShortcutSettings.create_shortcut();
if(快捷方式!=null){
CustomShortcutSettings.edit_快捷方式(快捷方式,快捷方式);
CustomShortcutSettings.edit_命令(快捷方式,ID);
}
}

它使用
CustomShortcutSettings
类来处理对系统设置的读取和写入。该类起源于另一个名为.

Oh的应用程序,因此它会自动在系统设置中注册一个全局快捷方式?聪明的我会在有时间的时候尝试这种方法,如果有效的话,我会给出反馈。