#!/usr/bin/perl -w use strict; # use some Win32 module for the task # the checking if anything been pressed logically combined with perl seems to me to look like my $trials = 20; # for 10 minutes while ($trials) { if (("mouse moved") or ("any key pressed")) { $trials = 20; # start the countdown all over again } else { $trials--; #decrease a trial sleep(30); #wait half a minute } } #now that $trials equals to 0 - therefore nothing been pressed for 10 minutes (20 halves of a minute {for better results}) doMyFunc($var1, $var2); sub doMyFunc { ... }