Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl/Tk: Is there a way to key off of any user input event?

by rcseege (Pilgrim)
on Oct 14, 2006 at 07:09 UTC ( [id://578257]=note: print w/replies, xml ) Need Help??


in reply to Perl/Tk: Is there a way to key off of any user input event?

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

Replies are listed 'Best First'.
Re^2: Perl/Tk: Is there a way to key off of any user input event?
by liverpole (Monsignor) on Oct 14, 2006 at 15:17 UTC
    If you're looking for any mouse movement, you could also just bind to the "<Motion>" event.  That would simplify your code even more:
    use Tk; use strict; use warnings; my $mw = MainWindow->new; $mw->bind('<KeyPress>', \&keyPress); $mw->bind('<Motion>', \&mouseMotion); MainLoop; sub quit { print "User triggered event -- exiting!\n"; exit; } sub keyPress { print "Debug: keypress occurred\n"; quit(); } sub mouseMotion { print "Debug: mouse motion occurred\n"; quit(); }

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

      Yep - I didn't think to try it out. For some reason, I was thinking it would only trigger events if it was over the widgets that had the binding.

      Thanks,

      Rob
Re^2: Perl/Tk: Is there a way to key off of any user input event?
by Argel (Prior) on Oct 16, 2006 at 22:26 UTC
    I'm not sure I completely understand what you want to achieve.

    My bad, throwing too much thin client jargon around. I have a wrapper script for the screensaver. I check if someone is using a thin client and if they are I disconnect the session instead of running the actual screensaver. Disconnected sessions remain running on the server until the user reconnects from a thin client (could be the same one or could be a different one). Think Citrix or Windows Terminal Services (I list Citrix first because guess who Microsoft got the technology from.... ;-)

    Management wants idle sessions locked or disconnected after 30 minutes. The problem is several users are looking at informantion on the thin client but not actually using them so the idle timeout kicks in and the session gets disconencted. Reconencting is annoying -- it's several seconds slower than just unlocking a screen saver. Thus, this script to warn them before it happens.

    Thanks for the help!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://578257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found