Skip to content

Instantly share code, notes, and snippets.

@kirsle
Last active December 25, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirsle/c4fea461359e8953dde1 to your computer and use it in GitHub Desktop.
Save kirsle/c4fea461359e8953dde1 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# requires: libX11-devel, libXt-devel, libXtst-devel, /usr/bin/xinput
# sudo cpanm X11::GUITest
use threads;
use IO::Pty::Easy;
use IO::Handle;
use X11::GUITest qw(ClickMouseButton :CONST);
# Use `xinput list` and find the ID num of your keyboard
my $id = 10;
my $kbd = threads->new(sub {
my $tty = IO::Pty::Easy->new();
$tty->spawn("xinput test $id");
print "Watching keyboard...\n";
my $start = time() + 2;
while ($tty->is_active) {
my $data = $tty->read();
if (time() > $start) {
print $data . "\n";
if ($data) {
print "Saw activity! Bail out!\n";
exit(0);
}
}
}
});
print "Get ready to click...\n";
sleep 5;
print "Clicking forever... hit any key to stop...\n";
while (1) {
select(undef,undef,undef,0.0005);
ClickMouseButton(M_LEFT);
}
print "Done!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment