From afcdc4f4b25f5568b4082d5c240bda1ea866d5e6 Mon Sep 17 00:00:00 2001 From: dscho Date: Thu, 15 Jun 2006 12:24:14 +0000 Subject: add timing --- VisualNaCro/recorder.pl | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/VisualNaCro/recorder.pl b/VisualNaCro/recorder.pl index bbe3f25..3b86e40 100644 --- a/VisualNaCro/recorder.pl +++ b/VisualNaCro/recorder.pl @@ -9,10 +9,12 @@ $output="my_script"; $server="localhost"; $port=5900; $listen_port=5923; +$timing=0; if(!GetOptions( "script:s" => \$output, - "listen:i" => \$listen_port + "listen:i" => \$listen_port, + "timing" => \$timing ) || $#ARGV!=0) { print STDERR "Usage: $ARGV0 [--script output_name] [--listen listen_port] server[:port]\n"; exit 2; @@ -20,6 +22,11 @@ if(!GetOptions( $output=~s/\.pl$//; +if ($timing) { + use Time::HiRes qw(time); + $starttime=-1; +} + $server=$ARGV[0]; if($server=~/^(.*):(\d+)$/) { @@ -55,6 +62,9 @@ open OUT, ">$output.pl"; print OUT "#!/usr/bin/perl\n"; print OUT "\n"; print OUT "use nacro;\n"; +if ($timing) { + print OUT "use Time::HiRes;" +} print OUT "\n"; print OUT "\$x_origin=0; \$y_origin=0;\n"; print OUT "\$vnc=nacro::initvnc(\"$server\",$port,$listen_port);\n"; @@ -64,6 +74,16 @@ $image_counter=1; $magickey=0; $x_origin=0; $y_origin=0; +sub writetiming () { + if ($timing) { + $now=time(); + if ($starttime>0) { + print OUT "nacro::process(\$vnc," . ($now - $starttime) . ");\n"; + } + $starttime=$now; + } +} + while(1) { $result=nacro::waitforinput($vnc,999999); if($result==0) { @@ -77,6 +97,7 @@ while(1) { $keysym=nacro::getkeysym($vnc); $keydown=nacro::getkeydown($vnc); if(nacro::sendkey($vnc,$keysym,$keydown)) { + writetiming(); print OUT "nacro::sendkey(\$vnc,$keysym,$keydown);\n"; } if($keysym==0xffe3 || $keysym==0xffe4) { @@ -98,6 +119,7 @@ while(1) { $buttons=nacro::getbuttons($vnc); if(nacro::sendmouse($vnc,$x,$y,$buttons)) { $x-=$x_origin; $y-=$y_origin; + writetiming(); print OUT "nacro::sendmouse(\$vnc,\$x_origin" . ($x>=0?"+":"")."$x,\$y_origin" . ($y>=0?"+":"")."$y,$buttons);\n"; -- cgit v1.2.1