[gtkmm] Grab key_pressed event



Hi,

I don't manage to grab all key events from a Gtk::Entry widget with
GdkEventKey.
It grabs only 'escape', 'F1 ... F12', Shift, Ctrl, ..., but don't grab any
other key as 'a...z', '1...0', ...
I want to grab when 'enter' key is pressed, but I think the Gtk::Entry
widget grabs it before and keep it for him.
I also tried the 'signal_changed' method of Gtk::Editable but it grabs
exactly the same keys as GdkEventKey.
Is there a way to grab such a key ?

In my app, it would by nice if I could grab 'escape' and 'enter' keys in
order to handle them in only one function.

thanks

Xavier


This is the code of my class which is the begining of a kind of console with
a Gtk::Entry to enter a command and a Gtk::TextView to print the result of
the command execution:

#include <gtkmm.h>
class CConsole_window : public Gtk::Window
{ 
public:
CConsole_window();
virtual ~CConsole_window();
protected:
//Signal handlers:
bool on_input_key_press_event(GdkEventKey* event);
Gtk::TextView Console_output;
Gtk::ScrolledWindow Console__scrolledwindow;
Gtk::Entry Console_input;
Gtk::VBox Console_vbox;
};

CConsole_window::CConsole_window()
{
Console_output.set_name("Console_output");
Console_output.set_flags(Gtk::CAN_FOCUS);
Console_output.set_editable(true);
Console__scrolledwindow.set_name("Console_ scrolledwindow");
Console__scrolledwindow.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
Console__scrolledwindow.add(Console_output);
Console_input.set_name("Console_input");
Console_input.set_flags(Gtk::CAN_FOCUS);
Console_input.set_visibility(true);
Console_input.set_editable(true);
Console_input.set_text(_(""));
file://add_events(Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);

// *** Don't grab all key pressed events, and particulary then 'enter' key pressed event I need ***
Console_input.signal_key_press_event().connect(slot(*this, &CConsole_window::on_input_key_press_event));


Console_vbox.set_homogeneous(false);
Console_vbox.set_spacing(0);
Console_vbox.set_name("Console_vbox");

Console_vbox.pack_start(Console__scrolledwindow);
Console_vbox.pack_start(Console_input, false, false, 0);
set_default_size(400,150);
set_name("Console_window");
set_title(_("Console"));
set_modal(false);
set_position(Gtk::WIN_POS_NONE);
add(Console_vbox);
Console_output.show();
Console__scrolledwindow.show();
Console_input.show();
Console_vbox.show();
show();
}

CConsole_window::~CConsole_window()
{
}

bool CConsole_window::on_input_key_press_event(GdkEventKey* event)
{

// *** I need to handle the 'escape' and 'enter' key pressed events in this
function ***

// I already take care of GDK_Escape because it is grabbed.
if(event->keyval == GDK_Escape) {
Glib::ustring str = Console_input.get_text();
g_print("%s", str.c_str());
return true;
}
return false;
}





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