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);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|