Skip to content

Instantly share code, notes, and snippets.

@kirsle kirsle/xclick.pl
Last active Dec 25, 2015

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.