Do you mean something like this? I'm not sure I completely understand what you want to achieve.
use Tk;
my $mw = MainWindow->new;
$mw->bind('<KeyPress>', \&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();
}
Other ideas... if you're using X-Windows, you might have a look at X11-IdleTime, you could call that from the repeat sub. You might also tie something in to your screensaver hook, so that it pops open a window, displays it and acts as a kind of an alert asking the user if he wants to keep the user session.
You'll probably want to build some sort of timer in case the user does nothing, and allow the session to die. I'm generally pretty leery about hacks designed to keep user sessions open. of thing. Having sessions expire is a good thing, although if that session time is too short, then it can be irritating. Too long, and it can effectively be a memory leak.
Rob