Here's a (slightly trimmed) script I use to control Winamp:
#!c:/perl/bin/perl -w
use strict;
use Win32::API;
use constant WM_USER => 1024;
use constant WM_COMMAND => 273;
my %commands = (
PREV => 40044,
NEXT => 40048,
PLAY => 40045,
PAUSE => 40046,
STOP => 40047,
# Lots of other commands trimmed for space...
);
my $cmd = uc shift;
if (exists $commands{$cmd}){
my $FindWindow = new Win32::API(
'user32',
'FindWindow',
['P', 'N'],
'I'
);
my $SendMessage = new Win32::API(
'user32',
'SendMessage',
['I', 'I', 'I', 'I'],
'I'
);
my $hwndWinamp = $FindWindow->Call('Winamp v1.x', 0);
$SendMessage->Call(
$hwndWinamp,
WM_COMMAND,
$commands{$cmd},
0
) if $hwndWinamp;
} else {
print "Invalid command.\n";
}
The most useful Winamp related script I have is the one that locks my computer and pauses Winamp. This snippet checks to see if Winamp is currently playing, and if so sends a "pause" command:
if ($hwndWinamp){
if ($SendMessage->Call($hwndWinamp,WM_USER,0,104) == 1) {
$SendMessage->Call($hwndWinamp,WM_COMMAND,40046,0);
}
}
--grummerX
|