use Tk; my $mw = MainWindow->new; $mw->bind('', \&keyPress); $mw->withdraw; my ($lastX, $lastY); $mw->repeat(400, [\&checkMouse, \$lastX, \$lastY]); $mw->focusForce; MainLoop; sub quit { print "User triggered event -- exiting!\n"; exit; } sub checkMouse { my ($lastX, $lastY) = @_; my $x = $mw->pointerx; my $y = $mw->pointery; $$lastX = $x unless defined $$lastX; $$lastY = $y unless defined $$lastY; quit() if $x != $$lastX; quit() if $y != $$lastY; } sub keyPress { quit(); }