Capture all key press events



Title: Capture all key press events

Hi All

I want to capture all the keys pressed on the keyboard before
sending the data to Gtk::Entry field.

right now, i am doing this:

signal_key_press_event().connect(sigc::mem_fun(*this,
&MyClass::key_pressed));

When the focus is on the Gtk::Entry field, this method captures non
alphanumeric-special characters such as F1-F12,Shift,Cntrl. I would like
to capture all the keys of the keyboard before they are sent to the
Entry field.

Below is the code snippet. All ur inputs are highly appreciated.

Thanks
Sirisha

MyClass.h
-----------
class MyClass :: public Gtk::Window {
        public:
                MyClass();
                ~MyClass();
                bool on_key_pressed(GdkEventKey *event);
                bool getBuffer(GdkEventKey *event);
        protected:
                Gtk::Entry m_pId;
};


MyClass.cpp
-------------
MyClass ::MyClass() {

        signal_key_press_event().connect(sigc::mem_fun(*this,
&MyClass::key_pressed));

        show_all_children();
}


bool MyClass::key_pressed(GdkEventKey *event)
{
   bool valid = false;
    if(!event)
          valid = false;

  switch (event->keyval)
  {
    case F1:
        F1Method();
        break;
    case F2:
        F2Method();
        break;
    case F3:
        F3Method();
        break;
    case F4:
        F4Method();
        break;
   default:
        valid = getBuffer(event);
        break;
  }     
valid = true;

}



bool MyClass::getBuffer(GdkEventKey *event)
{
        static eventCnt=0;
        static char buffer[256];
        buffer[evenCnt++]=char(event->keycode); 
        //do something with event and buffer
        return true;
}



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