willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476729

Enabling key event handling for gtk# (Mono)

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?

Upvotes: 2

Views: 1252

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476729

Found it myself:

You need to be able to focus on the Widget:

this.CanFocus = true;
this.Focus();

Upvotes: 3

Related Questions