On Wed, Feb 27, 2008 at 10:28 AM, obdulio santana
<[EMAIL PROTECTED]> wrote:
> I want to read the following keys [home][End][Pageup][Page down]
I think you're trying to capture an escape sequence, which is a series
of characters sent for certain keystrokes. I'm appending below an
example program that uses Term::ReadKey. The program isn't quite
correct, but I hope trying your keystrokes while it's running will
help you to get to the next step. Good luck with it!
--Tom Phoenix
Stonehenge Perl Training
#!/usr/bin/perl
use strict;
use warnings;
use Term::ReadKey;
sub readable {
my $result = '';
for my $char (split //, join '', @_) {
if ($char ge ' ' and $char le '~' and $char ne '\\') {
$result .= $char;
} else {
my $ord = ord $char;
if ($ord < 128) {
$result .= sprintf "\\x%02x", $ord;
} else {
$result .= sprintf "\\x{%x}", $ord;
}
}
}
$result;
}
END { ReadMode 'restore' }
ReadMode 'raw';
print "Type !!! to quit\n";
my $bang_count = 0;
while (1) {
my $input;
while (my $key = ReadKey -1) {
$input .= $key;
}
if (not defined $input) {
# nothing typed... wait a moment...
select(undef, undef, undef, 0.1);
} elsif (length($input) > 1 and $input =~ /^\e/) {
print qq{Escape sequence: "}, readable($input), qq{"\n};
} else {
if ($input eq '!') {
exit if ++$bang_count >= 3;
} else {
$bang_count = 0;
}
print qq{You typed "}, readable($input), qq{"\n};
}
}
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/