#!/usr/bin/env perl use v5.36; use strict; use X11::GUITest qw[GetMousePos MoveMouseAbs ClickMouseButton :CONST]; use Imager::Screenshot qw[screenshot]; use Carp; use Time::HiRes qw(sleep); ################# TUNEABLES ############# my $w = 1920; # Screen width my $h = 1080; # Screen height my $thingmakerx = 55; # leftmost X position of "Thing maker" list my $idealisterx = 1380; # leftmost X position of "Idea lister" list my $liststarty = 450; # Top Y of lists my $listendy = 1048; # Bottom Y of lists my $buttonx = 186; # Power button thingy X my $buttony = 369; # Power button thingy Y ################# TUNEABLES ############# my $lastx = -1; my $lasty = -1; while(1) { for(1..50) { click($buttonx, $buttony); } my $img = screenshot(); # Check idea lister my $ideasfound = findClickableStuff($img, $idealisterx, 'Idea lister', 1); if($ideasfound) { # Don't spend watts on thing maker when we still have ideas print "Still have ideas left!\n"; next; } # Check thing maker findClickableStuff($img, $thingmakerx, 'Thing maker', 1); } sub findClickableStuff($img, $startx, $name, $clickonlyone) { my $listitemsfound = 0; for(my $iy = $listendy; $iy > $liststarty; $iy--) { my $found = 0; for(my $ix = 0; $ix < 90; $ix++) { my ($r, $g, $b) = $img->getpixel(x => $ix + $startx, y => $iy)->rgba(); if($r == 255 && $g == 255 && $b == 255) { # White text (or lines): List has at least one entry $listitemsfound = 1; } #next if($r > 180); #next if($g < 180); # Search for somewhat green text (means we can affort the item) if($r < 50 && $g > 220 && $b > 150) { $found = 1; last; } } if($found) { print $name, "item found!\n"; for(1..3) { click($startx + 45, $iy); } $iy -= 50; #$listitemsfound = 1; if($clickonlyone) { last; } } } return $listitemsfound; } sub click($x, $y) { if($x != $lastx || $y != $lasty) { MoveMouseAbs($x, $y, 0); #sleep(0.5); $lastx = $x; $lasty = $y; } else { my ($mx, $my) = GetMousePos(); my $dist = abs($mx - $x) + abs($my - $y); if($dist > 10) { croak("USER ABORT!"); } } ClickMouseButton(M_LEFT); return; } exit(0);