#!/usr/bin/perl use warnings; use strict; use Glib; use Glib qw/TRUE FALSE/; use Term::ReadKey; $|++; ReadMode('cbreak'); my $main_loop = Glib::MainLoop->new; Glib::Idle->add( sub{ my $char; if (defined ($char = ReadKey(0)) ) { print "$char->", ord($char),"\n"; #process key presses here } return TRUE; #keep this going }); $main_loop->run; ReadMode('normal'); # restore normal tty settings __END__ #### #!/usr/bin/perl use warnings; use strict; use Term::ReadKey; $|=1; ReadMode('cbreak'); my $key = ''; while ( $key ne 'q' ) { while (not defined ($key = ReadKey(-1))) { # No key yet } print "Get key '$key'\n"; print ord($key); print "\n"; } __END__ while(1){ my $char; if (defined ($char = ReadKey(0)) ) { print "$char->", ord($char),"\n"; # input was waiting and it was $char } else { # no input was waiting } } ReadMode('normal'); # restore normal tty settings