Re: How do I intercept keys in a Gtk::Entry widget?



On Thu, 2008-09-25 at 08:58 -0700, Garth's KidStuff wrote:
Hey All,

I'd like to process the right arrow key in a Gtk::Entry widget (so, for
instance, if the cursor is at the rightmost insert position, I'd like to do
something special) but if I connect to the signal keypress event as so:

// LXWidgetEntry inherits from Gtk::Entry
LXWidgetEntry::LXWidgetEntry()
{
    signal_key_press_event().connect(sigc::mem_fun(*this,
&LXWidgetEntry::OnKeypress));
}

bool LXWidgetEntry::OnKeypress(
    GdkEventKey* event) // [in] event from the system (with key, state,
etc.)
{
    if (event->keyval == GDK_Right)
    {  // Do my thing here

    }
    return false;
}

I never get the right arrow key (I can get other keys, such as Tab, but not
keys the entry control uses).

You probably just need to handle the signal before the base
implementation (the GTK+ widget) does:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-xeventsignals.html#signal-handler-sequence

Once I get the key, how do I either let the widget continue to handle the
key in some of the cases?

That same section describes how you can use the return value to specify
that:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-xeventsignals.html

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]