Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Matts (1087)

Matts
  (email not shown publicly)

I work for MessageLabs [messagelabs.com] in Toronto, ON, Canada. I write spam filters, MTA software, high performance network software, string matching algorithms, and other cool stuff mostly in Perl and C.

Journal of Matts (1087)

Thursday September 07, 2006
12:21 PM

Shocking Presentations

[ #30914 ]

Just messing around with the Thinkpad Shock Manager. I decided to see if I could "next page" a presentation by whacking my laptop. It works :-)

use Win32API::File qw(:ALL);
use Win32::GuiTest qw(FindWindowLike GetWindowText
    SetForegroundWindow SendKeys);
 
$Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode
 
my @windows = FindWindowLike(0, "Mozilla Firefox", "");
 
die "No firefox open" unless @windows;
 
my $file = createFile("//./ShockMgr", "r ke") || die "createFile failed";
my @prev;
while(1) {
    DeviceIoControl($file, 0x733fc, [], 0, my($buf), 0x24, my($bytes), []);
    my ($x, $y, @extra) = unpack("x4s*", $buf);
    unless (arreq(\@extra, \@prev)) {
        print "Got: $x, $y\n@extra\n";
        my $text = GetWindowText($windows[0]);
        SetForegroundWindow($windows[0]);
        SendKeys("{DOWN}");
        sleep(1);
    }
    @prev = @extra;
    select(undef, undef, undef, 0.05);
}
 
sub arreq {
    my ($aa, $bb) = @_;
    for (0..$#$aa) {
        if ($aa->[$_] - $bb->[$_] > 5) {
            return;
        }
    }
    return 1;
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.