#!/usr/bin/perl use Term::ReadKey; #passing ReadKey() an argument of -1 to indicate not to block: ReadMode('cbreak'); while(1){ my $char; if (defined ($char = ReadKey(0)) ) { print "$char->", ord($char),"\n"; # input was waiting and i +t was $char } else { # no input was waiting } } ReadMode('normal'); # restore normal tty settings
#!/usr/bin/perl use warnings; use strict; use Tk; my $down = 0; my $mw = MainWindow->new; $mw->bind("<Key>", sub { &pressed } ); $mw->bind("<KeyRelease>", sub { &released } ); MainLoop; sub pressed{ my($widget) = @_; my $e = $widget->XEvent; # get reference to X11 event structure my $binding = 'Character = ' . $e->N . ', keysym = ' . $e->K . '.'; print "$binding\n"; print $e->K," pressed\n"; } sub released{ my($widget) = @_; my $e = $widget->XEvent; # get reference to X11 event structure my $binding = 'Character = ' . $e->N . ', keysym = ' . $e->K . '.'; print "$binding\n"; print $e->K," released\n"; }
In reply to Re: Binding keys to events?
by zentara
in thread Binding keys to events?
by tamaguchi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |