#!/usr/bin/perl use warnings; use strict; use Tk; #mouse must be positioned over "Exit" button for this to work. my $mw = MainWindow->new; $mw->bind( '' => \&print_keysym ); $mw->Button( -text => 'Exit', -command => sub { exit(); } )->pack; MainLoop; sub print_keysym { my $widget = shift; my $e = $widget->XEvent; my ( $keysym_text, $keysym_decimal ) = ( $e->K, $e->N ); print "keysym=$keysym_text, numberic=$keysym_decimal\n"; }