I'm playing around with gtkD (a D binding for GTK+)
我正在玩gtkD(GTK +的D绑定)
I have a window
object, instance of gtk.MainWindow
. I want to handle keypresses on it.
我有一个window对象,gtk.MainWindow的实例。我想处理它上面的按键。
- How?
- How do I deal with special keys (e.g. arrow keys, pgup/pgdn etc)?
我如何处理特殊键(例如箭头键,pgup / pgdn等)?
PS I know these kinds of questions can be answered with google and stuff, but I've seen much "simpler" questions on *, so I figured asking doesn't hurt.
PS我知道这些问题可以用谷歌和东西来回答,但我在*上看到了很多“更简单”的问题,所以我觉得问不伤。
Plus, sometimes, basic things tend to be burried under pages of documentation.
此外,有时,基本的东西往往被埋在文档页面下。
1 个解决方案
#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);
#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);