build::Keysyms(3)

πŸ“¦
version 1.24993 Β· 2 versions
, in fedora 43

πŸ’– build::Keysyms β€” the perl manual page, bestie edition πŸ’–

Okay so real talk: this is a page from the User Contributed Perl Documentation set, and it's filed under build::Keysyms(3) β€” but the actual module you're gonna use is called Gtk2::Gdk::Keysyms, and it's all about key codes for Gtk2 programs. Yes the name situation is a little chaotic, we love that for it. πŸŽ€


✨ NAME ✨

Gtk2::Gdk::Keysyms β€” key codes for Gtk2 programs πŸ¦‹


🌸 SYNOPSIS 🌸

use Gtk2;
use Gtk2::Gdk::Keysyms;

#
# the most common use is for deciphering keycodes in key events,
# like this:
#
sub key_press_handler {
        my ($widget, $event) = @_;
        if ($event->keyval == $Gtk2::Gdk::Keysyms{Escape}) {
                abort_whatever ();
                return 1;
        }
        elsif ($event->keyval == $Gtk2::Gdk::Keysyms{F1}) {
                do_help_thing ();
                return 1;
        }
        elsif ($event->keyval == $Gtk2::Gdk::Keysyms{KP_Enter}) {
                execute_selected_text_as_command ();
                return 1;
        }
        # we didn't handle it, pass it on...
        return 0;
}

Like, that's the whole vibe. You grab the keyval, you compare it to a named constant instead of a cursed mystery number, you slay. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

So Gdk defines symbolic names for the codes that are associated with each key on a keyboard β€” the entire point being that you do not go absolutely feral writing raw numeric values all over your programs. Nobody deserves that. 😭

The hash %Gtk2::Gdk::Keysyms holds all of those keycodes, indexed by the name, so your perl programs can use them whenever you need to do custom key handling. This comes up a lot when:

  • you wanna bind an action to a key that isn't usable as an accelerator,
  • you don't have accelerators at all,
  • you're trying to write an easter egg, πŸ™ˆ
  • or literally whatever, no judgement here.

The list of keycodes is quite large and rather rarely used in application code, so the devs put it in a separately-loaded module to save space. Iconic, honestly. 🫢

As an alternative, you might want to investigate "Gtk2::Gdk->keyval_from_name", which offers basically the same functionality as the hash. Two paths, same destination, pick your fighter. ⭐

And to get a list of all available keys? You've got options:

  1. dump %Gtk2::Gdk::Keysyms, or
  2. look at the source of this module with perldoc -m Gtk2::Gdk::Keysyms.

πŸ‘‘ AUTHOR πŸ‘‘

This module was automatically generated by a very simple perl script from gdk/gdkkeysyms.h.

And the closing line, which is genuinely a whole mood: "Programs that write programs are the happiest programs of all." πŸ˜­πŸ’– ate, no crumbs.


Copyright (C) 2003, 2009 by the gtk2-perl team (see the file AUTHORS for the full list)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Lowkey important bestie: that warranty disclaimer is doing heavy lifting. It's giving "we said what we said." πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

  • perl
  • Gtk2
  • Gtk2::Gdk

perl v5.42.0 ✨ 2025-07-25 ✨ and that's the build::Keysyms(3) energy, mwah πŸ’…πŸ’– go press some keys, bestie πŸŽ€

πŸ“¦ where this page comes from