Created
August 21, 2020 19:46
-
-
Save johannes-riecken/2baf640fa0bed2c0c16f4ef41c548473 to your computer and use it in GitHub Desktop.
Emulates bash's Ctrl-O for any console app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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