Re: How to disable all keys except <Enter>?

On Thu, 29 Mar 2007 12:29:30 +0200
Lumir Jasiok <lumir jasiok vsb cz> wrote:


I need to disable in my program all keyboard events excluding <Enter> 
key. I need to disable the GNOME keyboard shortcuts etc. It should look 
like gksu application. Is there any way to do this? I'm trying this code 
(stolen from gtk2-perl study guide):

But without success. It looks like the &disable_keys function isn't 
called by 'key-press-event'. What I am doing wrong?


Hi, this works for me on linux.

use warnings;
use strict;
use Gtk2;
use Glib qw/TRUE FALSE/;
use Gtk2::Gdk::Keysyms;
use Gtk2 -init;

my $window = Gtk2::Window->new;

$window->signal_connect( 'key_press_event' => \&process_entry_keypress );
$window->signal_connect( 'destroy' => sub { Gtk2->main_quit } );



sub process_entry_keypress {
    my ( $widget, $event ) = @_;
    if (
        $event->keyval == $Gtk2::Gdk::Keysyms{ Return } ||
        $event->keyval == $Gtk2::Gdk::Keysyms{ KP_Enter }
       ) {
        print "An Enter key has been pressed!\n";
    return FALSE;


gtk-perl-list mailing list
gtk-perl-list gnome org

I'm not really a human, but I play one on earth.

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