With a little help from an answer found here I was able to use below script to send keystrokes to the VGA console /dev/tty1
#!/usr/bin/perl
use warnings;
use strict;
open( my $TTY1 , '>' , '/dev/tty2' ) or die "Cannot open terminal for output: $!";
my $line = <STDIN>;
chomp($line);
for my $chr ( split( // , $line ) ) {
ioctl $TTY1 , 0x5412 , $chr or die "ioctl returned an error: $!";
}
# Wait a bit to allow for inspection of the result using setterm.
sleep 3;
# Then send an Enter.
my $chr="\n";
ioctl $TTY1 , 0x5412 , $chr or die "ioctl returned an error: $!";
close( $TTY1 );
It can be tested by:
echo -e 'date' | sudo /tmp/stdin2keyboard-buffer
And I check the current state of VGA console by:
watch sudo setterm -dump 2 -file /dev/stdout
where 2 represents the number that tty
returns on the vga console and should also be set as the right tty device in the open statement above. I can even send a Cursor Up followed by an enter and it runs the last command in shell history.
echo -e '\e[A' | sudo /tmp/stdin2keyboard-buffer
Now what I really would like to do, is to send Shift+PgUp to the console so I can see the scroll back of the VGA console too, but I can't seem to figure out the escape sequence for Shift PgUp.
Another approach would be to figure out how to dump the full buffer of /dev/vcsa, but either the device driver doesn't support that or I haven't figured out how to. In any case, the setterm binary doesn't support it.