Handling key presses in GTK+ (gtkD)

半世苍凉 提交于 2019-12-24 04:48:10

问题


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.


回答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);


来源:https://stackoverflow.com/questions/902349/handling-key-presses-in-gtk-gtkd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!