in reply to Can I capture string typING in STDIN without press enter?
#!/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; my $count = 1; my $timer = Glib::Timeout->add (1000, \&timer_callback, undef, 1 ); 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 sub timer_callback{ $count++; print "$count\n"; return 1; } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I capture string typING in STDIN without press enter?
by exilepanda (Friar) on May 30, 2012 at 14:46 UTC | |
by zentara (Cardinal) on May 31, 2012 at 10:39 UTC | |
by exilepanda (Friar) on Jun 01, 2012 at 16:24 UTC |