【发布时间】:2023-01-24 06:26:53
【问题描述】:
这是一个示例 GTK# 程序,它侦听按键并打印它们。
using Gtk;
using Application = Gtk.Application;
Application.Init();
Window win = new Window("Title");
win.DeleteEvent += (_, eventArgs) => Application.Quit();
win.KeyPressEvent += (_, eventArgs) =>
{
Console.WriteLine($"Key down {eventArgs.Event.Key}");
};
win.KeyReleaseEvent += (_, eventArgs) =>
{
Console.WriteLine($"Key up {eventArgs.Event.Key}");
};
win.Show();
Application.Run();
我希望看到进入按键,但我没有。相反,它们被映射以激活窗口的默认小部件。我可以禁用此功能以便进入按键也被按键侦听器捕获?
【问题讨论】:
-
您是否尝试过将 KeyPressEvent 掩码添加到窗口? IE。事件 |= Gdk.EventMask.KeyPressMask?