Re: [gtkmm] signal_key_press_event() question
- From: "Daniel J. Lauk" <Daniel Lauk Student FH-Reutlingen de>
- To: schwein chello nl, "gtkmm-list gnome org"@loginmail.fh-reutlingen.de, gtkmm-list gnome org
- Cc:
- Subject: Re: [gtkmm] signal_key_press_event() question
- Date: Thu, 07 Oct 2004 09:10:57 +0200
Hi.
First of all, I think, that your Gdk event handler is not doing all it should,
but I'm not sure.
Anyway, what you'd probably like is, to have the same behaviour as with a regular
Gtk::Entry except for the thing with the <ENTER> to <TAB> conversion, right?
I'm not absolutely sure on this, but you might like to experiment with the following
code:
<code>
bool NumberEntry::on_key_press_event(GdkEventKey* event)
{
/* first (if necessary) change the key code */
//36 = enter, 108 = keypad enter, 13 = tab
if (event->hardware_keycode==36 ||
event->hardware_keycode==108)
{
event->hardware_keycode = 13;
}
/* and now do, what Gtk::Entry would have done */
return Gtk::Entry::on_key_press_event(event);
}
</code>
Best regards,
DJ
>I want to catch a keypress of enter and turn it into a tab (to go to the
>next entry) to enable the user to quickly enter lots of numbers with the
>numerical keypad.
>
>Then i tried this code to catch a keypress in a Gtk::Entry, but this only
>works with non-printable keys (tab, function keys etc.)
>So i think that all printable characters get processed by the entry's
>on_key_press_event() and never make it to OnKeyPress() ?.
>
>class NumberEntry : public Gtk::Entry
>{ public:
> NumberEntry();
> ~NumberEntry();
> bool OnKeyPress(GdkEventKey* event);
>};
>
>NumberEntry::NumberEntry()
>{ signal_key_press_event().connect(sigc::mem_fun(*this,
>&NumberEntry::OnKeyPress));
>}
>
>bool NumberEntry::OnKeyPress(GdkEventKey* event)
>{ cout << "Pressed " << event->hardware_keycode << endl;
> return false;
>}
>
>
>I also tried overriding the on_key_press_event() function and was able to
>turn an enter into a tab, however no printable characters made it into the
>entry box.
>
>bool NumberEntry::on_key_press_event(GdkEventKey* event)
>{ cout << "Pressed " << event->hardware_keycode << endl;
> //36 = enter, 108 = keypad enter, 13 = tab
> if (event->hardware_keycode==36 || event->hardware_keycode==108)
> { event->hardware_keycode = 23;
> return on_key_press_event(event); //tab to next
> }
> return false;
>}
>
>i'm kinda stuck now, what am i doing wrong?, or is there maybe a much
>simpler way to achieve what i want?
>
>thanks for any help,
>Marco
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]