Re: hardware_keycode




On Saturday, September 13, 2003, at 09:30 AM, Jens Luedicke wrote:

I tried the recent 1.00 rc1 release and its
not possible for me to capture a key-press
event together with hardware_keycode.

how can I detect if enter was pressed?

depending on what you are trying to do, there are several ways.

if you want enter to activate a default response on a dialog, then you want to use the Gtk2::Dialog and set your desired response to be the default. http://developer.gnome.org/doc/API/2.0/gtk/GtkDialog.html#gtk-dialog- set-default-response

if you're not using a dialog, or not adding buttons to the dialog normally, you may need to make the buttons default-able -- use $widget->set_flags ('can-default') and then $widget->grab_default;

if you want pressing enter in an entry to activate the default button on a dialog, then use $entry->set_activates_default (1) . http://developer.gnome.org/doc/API/2.0/gtk/GtkEntry.html#gtk-entry-set- activates-default

if all of those are way off the mark and you're trying to do something else: the hardware_keycode member of the GdkEvent structure appears to be system-dependent, whereas the keyval member is not. thus, you want to use the keyval member with the mapping of keycodes provided by %Gtk2::Gdk::Keysyms, which you get by use'ing the Gtk2::Gdk::Keysyms module.

something like

     if ($event->keyval == $Gtk2::Gdk::Keysyms{'Return'}) {
          # user pressed return
     }

should do what you want.

a cheesy little key-watcher is attached; it shows how to use the keysyms.

Attachment: keytest.pl
Description: application/text



--
muppet <scott at asofyet dot org>


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