#!/usr/bin/perl use Term::ReadKey; use strict; use warnings; startListening(); #$| = 1; #$|++; #select(STDOUT); #$| = 1; sub startListening { # Disable CTRL keys ReadMode(4); my $word = ''; print "> "; while(1) { my $char; if (defined ($char = ReadKey(0))){ print $char; } my $ord = ord($char); last if ($ord == 3); if ($ord == 10 or $ord == 13) { # "Enter" enterPressed($word); $word = ""; print "> "; next; } elsif ($ord == 127) { # ie "Backspace" #chop($word); #print chr(8),' ',chr(8); print "BACKSPACE!\n"; next; } elsif ($ord == 27) { #clearstream(); #$ord="\0"; } elsif ($ord == 8) { print "BACKSPACE!\n"; } #if($ord != "\0"){ #$word .= chr($ord); #print '*'; #} } ReadMode(0); } sub clearstream { while(1) { my $char; if (defined ($char = ReadKey(-1)) ){}else{return} } return; } sub enterPressed { my $word = shift; print "WORD: " . $word . "\n"; }