Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Perl ScreenSaver

by beretboy (Chaplain)
on Feb 25, 2003 at 14:37 UTC ( #238437=perlquestion: print w/replies, xml ) Need Help??
beretboy has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on some distributed computing projects and it would be very convienent to run the clients in the form of a screensaver (like SETI@Home). I found this node, which was helpful but I still need to figure out how to make the program exit upon mouse or keyboard activity. The target platform in this case is Windows. Any help would be greatly appreciated!

"Sanity is the playground of the unimaginative" -Unknown

Replies are listed 'Best First'.
Re: Perl ScreenSaver
by tall_man (Parson) on Feb 25, 2003 at 16:21 UTC
    perl/Tk applications will work on Windows, and you can easily bind mouse and keyboard activity to exit the program.
    use strict; use Tk; my $mw = new MainWindow(); ... $mw->bind("<Motion>",sub { $mw->destroy }); MainLoop;
      Thanks thats perfect!

      "Sanity is the playground of the unimaginative" -Unknown
        post code or email to
Re: Perl ScreenSaver
by phydeauxarff (Priest) on Feb 25, 2003 at 16:19 UTC
    Interesting question....not a windows programmer myself but I believe what you are needing to do is catch the interupt event from the mouse, or better yet from mouse and/or keyboard.
    did some CPAN searching to see if there was already a module that could do this and SDL::Event seems to have some promise and appears to be quite flexible in the type of events you can capture.
    Though I don't know that I would approach this in Perl (crouches as the monks gasp at his heresy) does sound like an facinating exercise to try
Re: Perl ScreenSaver
by paulbort (Hermit) on Feb 25, 2003 at 16:19 UTC
    I'm just learning Perl::Tk, but I'm guessing that you will need to do something like trap all keyboard and mouse events on the main window, and minimize on any event. You should probably also watch for the main window losing focus, which could indicate a system keystroke like SAS (Secure Attention Sequence) or the "Windows" key. If you can bear to read VB, Microsoft has an example of the API calls.
    Spring: Forces, Coiled Again!
Re: Perl ScreenSaver
by guha (Priest) on Feb 25, 2003 at 20:57 UTC

    When I read Perl && mouse && keyboard events I seem to recall having seen a module named Win32::Console with those specs. It is distributed with Activestate's Perl v633.

    No I have not tried it myself, but it seems to be well documented so why don't you check it out.

Re: Perl ScreenSaver
by Ionizor (Pilgrim) on Feb 26, 2003 at 15:54 UTC

    An alternative approach that might serve you just as well is to make your program run all the time but set the priority to "Idle". This way it stays running in the background whenever there are spare CPU cycles meaning you never have to exit. I've seen some benchmarks done on Folding@Home which uses this approach and the impact of the client on system performance is negligable.

    I'm guessing this throws all hope of cross platform compatability out the (heh) window but it didn't seem to be an important consideration...

    Grant me the wisdom to shut my mouth when I don't know what I'm talking about.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://238437]
Front-paged by broquaint
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-05-28 17:58 GMT
Find Nodes?
    Voting Booth?