views:

23

answers:

1

I'm trying to intercept events using Gdk.Window.AddFilter(Gdk.FilterFunc) in Mono. So far, I have been able to hook up the filter function, but now I am trying to use the events in the filter function.

This is what I have in the filter function so far:

private Gdk.FilterReturn FilterFunction(IntPtr xEvent, Gdk.Event evnt)
{
    if (evnt.Type == Gdk.EventType.KeyPress)
    {
        Gdk.EventKey eventKey = (Gdk.EventKey)evnt; // fails here

        if (eventKey.Key == this.key && eventKey.State == this.modifiers)
        {
            this.OnPressed(EventArgs.Empty);
        }
    }

    return Gdk.FilterReturn.Continue;
}

How can I convert the Gdk.Event to Gdk.EventKey? I have tried casting it, but that doesn't seem to work.

Edit: Oops! The problem was that I had accidentally added a semicolon to the if statement, making it an empty statement. For some reason, the Gdk.Event does not correspond to the XEvent, so I am now pursuing a solution that uses the XEvent instead.

+1  A: 

Why don't you try printing out the type so you can see what it really is? (it may not be EventKey)

Like:

Console.WriteLine (evnt.GetType ());

(or pause it in a debugger and examine it to see the type)

jpobst
Thanks! It wasn't `EventKey`.
Zach Johnson