2

I'm playing around with gtkD (a D binding for GTK+)

I have a window object, instance of gtk.MainWindow. I want to handle keypresses on it.

  • How?
  • How do I deal with special keys (e.g. arrow keys, pgup/pgdn etc)?

PS I know these kinds of questions can be answered with google and stuff, but I've seen much "simpler" questions on stackoverflow, so I figured asking doesn't hurt.

Plus, sometimes, basic things tend to be burried under pages of documentation.

hasen
  • 161,647
  • 65
  • 194
  • 231

1 Answers1

1

Here is sample code which may help

import gdk.Keysyms; //keys enums are defined here

private void func(Button sender)
{
    //button pressed
}

but.addOnClicked(&func);

private bool func2(GdkEventKey* ev, Widget sender)
{
    if(ev.keyval == GdkKeysyms.GDK_Tab) 
        return true; //we handle Tab ourselves and prevents default behaviour
    else
        return false; //we didnt handle it so gtk does default behaviour
}

win.addOnKeyPress(&func2);
Tim Matthews
  • 5,031
  • 8
  • 38
  • 45
  • Thanks! Though `&func` didn't work, as it expects a delegate. – hasen May 26 '09 at 00:26
  • How do you mean? I have something compiled and working right now here but in my code those are defined on my windows class and up calling the addOnClicked from the ctor. Maybe thats why. – Tim Matthews May 26 '09 at 04:46