If you've ever wanted to see how fast a remote controlled car can actually go (or you are bored and want to see how fast you can spin your mouse wheel) this script is for you.
This script measures how fast the mouse wheel is spinning and translates that into miles per hour (when I'm bored I write stuff in perl).
Note: The script is calibrated for a Microsoft Wireless IntelliMouse Explorer 2.0
use warnings;
use strict;
use Tk ':variables';
use Time::HiRes;
my $clicksPerRevolution = 17; #how many numbers are sampled in one com
+plete revolution of the mouse wheel
my $wheelArea = 4.75; #how many inches are in one complete revolution
+of the mouse wheel
my $clicksPerMile = (63360/$wheelArea)*$clicksPerRevolution; #63360 in
+ches in a mile
my $mouseWheel = 0;
my ($previousClickTime, $currentClickTime);
my $maxSpeed = 0;
my $mw = MainWindow->new();
my $lbl1 = $mw->Label(-text => 'Max MPH');
my $lbl2 = $mw->Label(-textvariable => \$maxSpeed);
my $lbl3 = $mw->Label(-text => 'Current MPH');
my $lbl4 = $mw->Label(-textvariable => \$mouseWheel);
$lbl1->grid(-row => '0', -column => '0');
$lbl2->grid(-row => '0', -column => '1');
$lbl3->grid(-row => '1', -column => '0');
$lbl4->grid(-row => '1', -column => '1');
$mw->bind('<MouseWheel>' => \&mph );
$mw->bind('<4>' => \&mph ); #zentara
$mw->bind('<5>' => \&mph ); #zentara
$mw->MainLoop();
sub mph{
$previousClickTime = $currentClickTime;
$mouseWheel = $Tk::event->XEvent;
$incr++;
($seconds, $microseconds) = Time::HiRes::gettimeofday();
$currentClickTime = $microseconds;
if ($incr > $clicksPerRevolution){
$incr = 1;
}
$microSecondsBetweenClicks = $currentClickTime-$previousClickTime;
if (eval{ $mouseWheel = sprintf '%.2f', (1/$clicksPerMile)/($micro
+SecondsBetweenClicks/3600000000); }){}
if ($mouseWheel > $maxSpeed && $mouseWheel < 600){
$maxSpeed = $mouseWheel;
}
}
sub arrPush{
my $value = shift;
push (@avgArray, $value);
}