L
lucas
I'm using Term::ReadKey, and I'm not sure why, but it prints out extra
characters, every few characters, it'll print out an extra byte, as you can
see below:
bash-2.05a$ perl x
abccdefgg << this is what is displayed
[abcdefg] << this is what was actually typed
I pulled this out of my program, and I can recreate the problem exactly with
this:
use Term::ReadKey;
open(TTY, "</dev/tty"); #read from terminal (keyboard)
my $ttybuf = '';
while (1) {
ReadMode "raw";
if($key = ReadKey -1, *TTY) {
ReadMode "normal";
if (ord($key) == 27) { die "\nEscaping\n"; }
elsif (ord($key) == 3) { die "\nSIGINT Caught\n"; }
elsif (ord($key) == 127){ print "\x08\x20\x08"; chop($ttybuf); }
#print destructive backsapce
else {
print $key; #<<<this is the line that prints out each key stroke
if (ord($key) == 10) { print "[$ttybuf]\n"; undef($ttybuf); }
else { $ttybuf .= $key; } #save all keystrokes in buffer
}
}
else { ReadMode "normal"; }
}
I've been hammering at this for awhile, but I can't figure out why extra
bytes are printed out. If there is a better way, or a fix, plz let me
know, and if you can think of a better destructive backspace, paste it
thx
characters, every few characters, it'll print out an extra byte, as you can
see below:
bash-2.05a$ perl x
abccdefgg << this is what is displayed
[abcdefg] << this is what was actually typed
I pulled this out of my program, and I can recreate the problem exactly with
this:
use Term::ReadKey;
open(TTY, "</dev/tty"); #read from terminal (keyboard)
my $ttybuf = '';
while (1) {
ReadMode "raw";
if($key = ReadKey -1, *TTY) {
ReadMode "normal";
if (ord($key) == 27) { die "\nEscaping\n"; }
elsif (ord($key) == 3) { die "\nSIGINT Caught\n"; }
elsif (ord($key) == 127){ print "\x08\x20\x08"; chop($ttybuf); }
#print destructive backsapce
else {
print $key; #<<<this is the line that prints out each key stroke
if (ord($key) == 10) { print "[$ttybuf]\n"; undef($ttybuf); }
else { $ttybuf .= $key; } #save all keystrokes in buffer
}
}
else { ReadMode "normal"; }
}
I've been hammering at this for awhile, but I can't figure out why extra
bytes are printed out. If there is a better way, or a fix, plz let me
know, and if you can think of a better destructive backspace, paste it
thx