Is there something similar to keypad(1) outside from Curses?
I would like to write something like this, but without using Curses and without handling the escape sequences myself.
#!/usr/bin/env perl
use warnings;
use 5.012;
use Curses;
initscr();
raw();
printw( qq{Press "Delete"} );
noecho();
keypad(1);
my $c = getch();
endwin();
if ( $c =~ /\A330\z/ ) {
say "OK";
} else {
say qq{You didn't press "Delete"};
}
When I use Term::ReadKey it behaves different:
#!/usr/bin/env perl
use warnings;
use 5.012;
use Term::ReadKey;
ReadMode('raw');
print qq{Press "Delete" };
while ( 1 ) {
my $c = ReadKey( 0 );
last if $c eq 'q';
say "<$c>";
}
ReadMode('normal');
Output after pressing “Delete”:
Press "Delete" <
<[>
<3>
<~>
What is it about Curses that you want to avoid?
You may find Term::TermKey useful. It is a Perl interface to the libtermkey library, which handles keyboard control characters and multi-byte escape sequences and UTF-8 characters.