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);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|