当用户按下某个键时,以下代码不会触发KeyPress
事件...
public class FooWidget : DrawingArea {
public FooWidget () {
this.AddEvents ((int)Gdk.EventMask.KeyPressMask);
}
[GLib.ConnectBefore]
protected override bool OnKeyPressEvent (Gdk.EventKey evnt) {
Console.WriteLine (evnt);
return base.OnKeyPressEvent (evnt);
}
}
出了什么问题?
答案 0 :(得分:2)
自己找到它:
您需要专注于Widget
:
this.CanFocus = true;
this.Focus();