문제

The following code does not trigger the KeyPress event when the user presses a key...

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);
    }

}

What is going wrong?

도움이 되었습니까?

해결책

Found it myself:

You need to be able to focus on the Widget:

this.CanFocus = true;
this.Focus();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top