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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Use your mouse wheel as a dynamometer
by zentara (Cardinal) on Sep 28, 2011 at 17:21 UTC | |
by coderama (Novice) on Sep 29, 2011 at 11:49 UTC | |
by zentara (Cardinal) on Sep 29, 2011 at 12:39 UTC | |
Re: Use your mouse wheel as a dynamometer
by ssandv (Hermit) on Sep 29, 2011 at 22:27 UTC | |
Re: Use your mouse wheel as a dynamometer
by Discipulus (Canon) on Sep 29, 2011 at 08:26 UTC | |
Re: Use your mouse wheel as a dynamometer
by hominid (Priest) on Sep 28, 2011 at 17:26 UTC | |
Re: Use your mouse wheel as a dynamometer
by PhilipJ (Initiate) on Oct 20, 2011 at 17:01 UTC |