VNC snapshot

Brian Theado 03Oct2004 Here is some code you can use to spy on yourself as you work on the computer. Useful if you often finds hours of computer time pass with nothing useful accomplished. Just take a look at the slideshow of screenshots to identify where all the time has been wasted.

This code is based uses the tkvnc. Tkvnc is an application and not a library and so I just override some of the functionality. Instead of displaying the images, it saves them to disk. Also, instead of requesting screen updates as fast as possible, it only requests updates every 30 seconds. To use it, download tkvnc.kit [L1 ] and download and run a vnc server. I used the winvnc server from http://ultravnc.sourceforge.net/ . I had to enable receiving connections from localhost (can be done via the gui configuration) and I chose to disable connections from other than localhost (must be done by editing the registry--ugh!).

I am aware of tclrfb and the example client supplied didn't work out of the box like tkvnc. I took the easy route and used tkvnc.

After writing this code I discovered such functionality already exists with nice command-line options at http://vncsnapshot.sourceforge.net/ (and http://www.unixuser.org/~euske/vnc2swf/ ?).

 source tkvnc.kit ;# sdx version: 2003/01/20 13:44:32  33581-29437
 namespace eval ::vnc {
    # Don't display the vnc captured images
    pack forget $CANVAS
    $CANVAS delete screen
    
    # As soon as an update is received and has been processed, tkvnc immediately 
    # requests another update.  Override that behavior to only request updates once 
    # in a while.
    rename FBUpdateRequest FBUpdateRequest.orig
    proc FBUpdateRequest args {
        after 30000 [namespace code [concat FBUpdateRequest.orig $args]]
        }

    # Once an update has been received and processed, save the image to a file
    rename FBUpdate FBUpdate.orig
    proc FBUpdate args {
        eval FBUpdate.orig $args
        variable SCREEN
        variable snapshotprefix
        $SCREEN write [file join $snapshotprefix [clock seconds].gif]
        }
    
    set snapshotprefix c:/temp/vnc-snap/

    # Uncomment this to automatically establish a connection, or just use
    # the menu pick to establish the connection
    # attach 127.0.0.1 5900 yourvncpasswordhere
    }