我正在使用gtk-3.0创建我的简单UI,我想通过 g_signal_emit(...)函数向GTKEntry发送假事件。 实际上,我不知道,我应该将哪些参数传递给这个函数。
答案 0 :(得分:1)
来源:https://mail.gnome.org/archives/gtkmm-list/2007-June/msg00115.html
void Foo:bar() // handler for signal_clicked()
{
<YOUR TREEVIEW>.grab_focus(); // essential
guint keyval = GDK_Page_Down;
GdkKeymapKey* keys;
gint n_keys;
gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
keyval,
&keys,
&n_keys);
// Note: GdkEvent is an union
GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
((GdkEventKey*)event)->window =
<YOUR TREEVIEW>get_window()->gobj();
((GdkEventKey*)event)->send_event = TRUE;
((GdkEventKey*)event)->time = GDK_CURRENT_TIME;
((GdkEventKey*)event)->state = GDK_KEY_PRESS_MASK;
((GdkEventKey*)event)->keyval = keyval;
((GdkEventKey*)event)->hardware_keycode = keys[0].keycode;
((GdkEventKey*)event)->group = keys[0].group;
gdk_event_put(event);
// Or, more gdkmm-ish:
// Gdk::Event(event).put();
}