Re: how to add a key-press event




Lich Lee said:
hi!  This is my first letter here.

welcome.

I've try to add a key-press event to a entry object by signal
I did this;
......
$key = Gtk2::Gdk::Event('key-press');
$key -> keyval(105);
$entry -> signal_connect($key => \&CallMeHere);

that doesn't do what you want.  i imagine it said something to the effect of
"<garbage> is not a valid signal for GtkEntry".  $key there should actually be
a signal *name*.

the signal name must be something definite; the signal names are listed in the
pod for each object.  the signal you want for a key-press event is, oddly
enough, "key-press-event".  (you can use either - or _, the bindings treat
them as equivalent.)

once you're inside the key-press-event handler, you peek inside the event to
see whether the key was the one you wanted.

  $entry->signal_connect (key_press_event => \&key_handler);

  sub key_handler {
      my ($widget, $event) = @_;

      # match the keyval --- in general you don't want to use magic
      # numbers here, use values from %Gtk2::Gdk::Keysyms instead.
      if ($event->keyval == 105) {
          # insert special handling here
          return TRUE;  # tell the system we handled this
      }

      return FALSE;  # tell the system we did not handle this
  }


the Gtk2/examples contain some examples of doing this.


-- 
muppet <scott at asofyet dot org>



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