Skip to content

Instantly share code, notes, and snippets.

@johannes-riecken
Created August 21, 2020 19:46
Show Gist options
  • Save johannes-riecken/2baf640fa0bed2c0c16f4ef41c548473 to your computer and use it in GitHub Desktop.
Save johannes-riecken/2baf640fa0bed2c0c16f4ef41c548473 to your computer and use it in GitHub Desktop.
Emulates bash's Ctrl-O for any console app
my $last_cmd = '';
my $up_cnt;
sub up {
if ($last_cmd ne 'up') {
$up_cnt = 0;
}
`sleep 0.2s;xte 'key Up'`;
$last_cmd = 'up';
$up_cnt++;
warn $up_cnt;
()
}
sub op_get_next {
`xte 'key Return'`;
my @ups = ("\x27key Up\x27") x $up_cnt;
`sleep 0.2s;xte @ups`;
$last_cmd = 'op_get_next';
()
}
sub on_action {
my ($self, $action) = @_;
if ($action eq 'up') {
$self->up();
} elsif ($action eq 'op_get_next') {
$self->op_get_next();
}
()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment