Re: Questions on Key-Press Event
- From: Bob Caryl <bob fis-cal com>
- To: Bob Caryl <bob fis-cal com>
- Cc: Efrat Regev <efrat_regev yahoo com>, gtkmm-list gnome org
- Subject: Re: Questions on Key-Press Event
- Date: Mon, 17 Oct 2005 09:27:38 -0500
Once again, I apologize for how Thunderbird managles links.
Bob
Bob Caryl wrote:
Hello,
I have several applications that use more than one window. I
implemented context sensitive help by using the following in the
constructor for the main application window:
// code snippet
Gtk::Main::signal_key_snooper().connect(sigc::mem_fun(*this,&<your
window class name::your callback slot>));
///////////////////////
where "your window class name" is what it describes, as well as "your
callback slot." In the callback slot connected to this signal, you
can intercept any keystroke you like, then return 1 so the regular
keystroke handlers will ignore the keystroke, or 0 to allow this event
to be passed along to them.
The callback syntax is like this:
// code snippet
sigc::slot< int, Widget *, GdkEventKey * >
/////////////////////////////////////////////
or:
// code snippet
int <your widget class name>::<your callback slot name>(Gtk::Widget
*,GdkEventKey *)
{
... your code goes here
}
///////////////////////////////////////////
The widget pointer passed to your function points to the widget that
had focus when the key was pressed.
GdkEventKey is as follows:
// code snippet
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
guint state;
guint keyval;
gint length;
gchar *string;
guint16 hardware_keycode;
guint8 group;
} GdkEventKey;
///////////////////////////////////////////
Describes a key press or key release event.
GdkEventType <cid:part1.01000202.04020205@fis-cal.com> /type/; the
type of the event (GDK_KEY_PRESS or GDK_KEY_RELEASE).
GdkWindow <cid:part2.04000809.05080203@fis-cal.com> */window/; the
window which received the event.
gint8 <cid:part3.09050804.02010101@fis-cal.com> /send_event/; TRUE
if the event was sent explicitly (e.g. using XSendEvent).
guint32 <cid:part4.04020206.09030901@fis-cal.com> /time/; the time
of the event in milliseconds.
guint <cid:part5.06070804.09090804@fis-cal.com> /state/; a
bit-mask representing the state of the modifier keys (e.g. Control,
Shift and Alt) and the pointer buttons. See GdkModifierType
<cid:part6.01030209.08030201@fis-cal.com>.
guint <cid:part5.06070804.09090804@fis-cal.com> /keyval/; the key
that was pressed or released. See the <gdk/gdkkeysyms.h> header file
for a complete list of GDK key codes.
gint <cid:part8.05050907.05060706@fis-cal.com> /length/; the
length of /string/.
gchar <cid:part9.07020608.06070005@fis-cal.com> */string/; a
string containing the an approximation of the text that would result
from this keypress. The only correct way to handle text input of text
is using input methods (see GtkIMContext
<cid:part10.05080800.07080200@fis-cal.com>), so this field is
deprecated and should never be used. (gdk_unicode_to_keyval()
<cid:part11.08050709.03050102@fis-cal.com> provides a non-deprecated
way of getting an approximate translation for a key.) The string is
encoded in the encoding of the current locale (Note: this for
backwards compatibility: strings in GTK+ and GDK are typically in
UTF-8.) and NUL-terminated. In some cases, the translation of the key
code will be a single NUL byte, in which case looking at /length/ is
necessary to distinguish it from the an empty translation.
guint16 <cid:part12.00000809.07050707@fis-cal.com> /hardware_keycode/;
the raw code of the key that was pressed or released.
guint8 <cid:part13.01050009.09090503@fis-cal.com> /group/; the
keyboard group.
I use the "keyval" field of this structure in my application. The
above information tells you which include file has all the key values
defined.
I hope this helps a little bit.
Bob
Efrat Regev wrote:
Hello,
I'm having some difficulty with key-press events,
and haven't been able to find answers in the mailing
list, docs, faqs, etc. I'd very much appreciate any
help.
My main window has a menu-bar, tool-bar, and other
widget children. I'm trying to capture the events of
the keyboard's arrows being pressed (since the
application is a simple game). My main window
overrides
virtual bool
my_main_wnd::on_key_press_event(GdkEventKey *p_event).
This doesn't work (for me), due to two reasons:
A. When my main window overrides on_key_press_event, I
get notified of these events, but the keyboard has no
effect on the window's menu. When I erase the
override, however, the menu works fine with the
keyboard. Is there a way to both get the key-press
event and have the menu working properly?
B. In on_key_press_event, I switch(){} on
p_event->keyval. I'm checking for cases such as case
GDK_leftarrow:, but when I press the left key I get a
different value (65361), not the one I expect
(GDK_leftarrow). What should I write in the case _:,
therefore?
Again, many thanks for you time. Additionally,
thanks to all those who contributed to this awesome
ass-kicking library!
__________________________________ Yahoo! Music Unlimited Access over
1 million songs. Try it free.
http://music.yahoo.com/unlimited/
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]