RE: [gtkmm] Key press events not captured for some keys



You might try using connect_notify() instead of connect(), to handle the
signal before anything else does. That's the gtkmm equivalent of
connect_before for GTK+.

Here is a similar problem:
http://bugzilla.gnome.org/show_bug.cgi?id=125969

I don't think that you can ever handle the key event before the window
manager does.

Please send emails as text rather than HTML.

Murray Cumming
www.murrayc.com
murrayc usa net 

-----Original Message-----
From: gtkmm-list-admin gnome org [mailto:gtkmm-list-admin gnome org] On
Behalf Of Ramachandra Putti
Sent: Donnerstag, 29. Januar 2004 05:43
To: gtkmm-list gnome org
Cc: Vijay D; Nilesh S; Pramod S; Manjit D; Subramaniam R; Nishikant K;
Girish P; Manoj K
Subject: [gtkmm] Key press events not captured for some keys


Hi all,

I have developed a gtkmm application under Redhat Linux 7.3, gcc 2.96 
and gtkmm 2.0, that shows a simple window.I am trying to obtain key press 
events on the window.

I am using "on_key_press(GdkEvent *key)" method to get the values of key 
pressed, what i found was that for keys like "Enter", "Space Bar" and  all 
arrow keys, no event key_press is generated.

I wrote on_key_release_event(GdkEvent *key), the same keys "Enter", 
"Space bar" and  all arrow keys. It  generates the release event only. i.e.
no key 
press event is generated, but the release event is fired.

I also noticed that for system reserved keys in KDE, like ALT-F1 for Run
command, CTRL-f2 is for desktop 2, when I pressed these keys, the system
executes them for its use before I can capture it.

So my query is,
1. What is the code for capturing key press events ?
2. How to catch the system reserved keys before their execution by the
system ?

Below is Code snippet for you to try out what I have stated above,

Any help would be great appreciated,

Regards,
Ramachandra



#include <stdio.h>
#include <gdkmm/gc.h>
#include <gdk/gdkkeysyms.h>
#include <gtkmm/window.h>
#include <gtkmm/main.h>
class CWindow: public Gtk::Window
{

  public:
CWindow();
~CWindow();

bool on_window1_key_press_event(GdkEventKey *Key);
bool on_window1_key_release_event(GdkEventKey *Key);
};

CWindow::CWindow(): Gtk::Window(Gtk::WINDOW_TOPLEVEL)
{
Gtk::Window *window1 = this;
   window1->set_title("window1");
   window1->set_modal(false);
   window1->set_position(Gtk::WIN_POS_NONE);
   window1->show();

window1->signal_key_press_event().connect(SigC::slot(*this,&CWindow::on_wind
ow1_key_press_event));

window1->signal_key_release_event().connect(SigC::slot(*this,&CWindow::on_wi
ndow1_key_release_event));
}
CWindow::~CWindow()
{
}
bool CWindow::on_window1_key_press_event(GdkEventKey *Key)
{
printf("\n Key Presssed is %s\n",gdk_keyval_name(Key->keyval));
return true;
}

bool CWindow::on_window1_key_release_event(GdkEventKey *Key)
{
printf("\n Key Released is %s \n",gdk_keyval_name(Key->keyval));
return true;
}


int main(int argc, char **argv)
{

    Gtk::Main m(argc, argv);
CWindow *ptrWindow = new class CWindow();
m.run(*ptrWindow);
delete ptrWindow;
ptrWindow = 0;
return 0;
}



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