OK, I'll admit it. I have love-hate relationship with Winamp. When I starting using Winamp back in the version 2.x days (late 1990's), the program was a small, simple, and lightweight music player. I thought it was a thing of beauty. Over the years, Winamp has gone through a large number of changes (both good and bad) to become a feature-packed multi-media player.
Although the most recent versions of Winamp are bloated with extra plug-ins and junk that I don't want or need, I still like the program and use it on a daily basis. To help speed up the program, I unload most of the extraneous plug-ins. Don't get me wrong. Winamp is not my only media player. Winamp's video player is somewhat limited so I use jetAudio to play most of my video and Windows Media Player to play the tiny few formats that jetAudio doesn't support. But when comes to music, Winamp is still my player of choice.
When I started using AutoHotkey a few months back, writing code to control Winamp was a natural application. Using the examples in the AHK help file, I had some luck sending commands to Winamp (via ControlSend), but I had a lot of problems executing these commands when Winamp was active. Also, Winamp's use of multiple windows (some hidden) and window titles proved to be a pain in the butt.
Later while browsing through the forum, I stumbled on to some old posts that discuss the SendMessage commands supported by Winamp. Although not a perfect solution (not all of the commands work for all Winamp versions), the SendMessage commands proved to be a more complete solution. Here are just a few of posts (not all of them) that I found that use PostMessage/SendMessage to communicate with Winamp:
http://www.autohotke...topic.php?t=115 (The original)
http://www.autohotke...topic.php?t=177
http://www.autohotke...topic.php?t=239
http://www.autohotke...opic.php?t=2258
http://www.autohotke...opic.php?t=4612
http://www.autohotke...opic.php?t=4916The problem with using PostMessage/SendMessage command to control Winamp (or any application for that matter) is that the message parameters are very cryptic. For example, what the heck does this do?
SendMessage 0x0111,40001,,,ahk_class Winamp v1.xIf you've commented your code correctly, you would have noted that this message closes the Winamp application. You were only able to code this command by extracting it from someone else's code/posts (that's what I did) or by downloading the Winamp SDK, extracting the message information from the code, and use the AHK help file or Rajat's SendMessage tutorial to code it into AHK (did that too!)
Finally getting around to it...
To make controlling Winamp a bit easier to code for, I've written an "all inclusive" Winamp function that uses English (or any language if converted) word(s) as parameters to communicate/control Winamp. By "all inclusive", I mean that if there is anything you want to check or do with Winamp, you put into the Winamp function.
The Winamp function currently does simple window checks (if exist, if active, etc.), simple window commands, (activate, close, etc.), and some of the more popular SendMessage commands supported by Winamp. I could have included all possible commands but that would have bloated the code into an unmanageable monster so I only included the commands that I use or commands that I thought I might use in the future.
I refer to the function as a "shell" because the code was written so that anyone can be easily modify it to include any commands (or aliases) that I did not include. If you want to add a Winamp message that wasn't included, you still have to do your homework to find the appropriate message number, but the rest of the code to format and send the message should already be included.
Here are a few examples of how this this function can be used in a script:
^#!Up::Winamp("Play") ;-- Nothing will happen if Winamp is not running. ^#!Down:: if Winamp("Exist") ;-- Winamp running? if Winamp("Is Playing")=1 ;-- Winamp playing? (Check to avoid Pause toggle) Winamp("Pause") return ^#!Left::Winamp("Previous Track") ;-- Go back 1 track ^#!Right::Winamp("Next Track") ;-- Skip to the next trackThe code is not completely mature (never will be) but I'm tired of working on it and I wanted to share it before I forget. Of course, I've only tested this code on my version of Winamp (5.11) and on my OS (XP Pro SP2) but it should work for most.
The Code
The pertinent files are as follows:
Source code: Winamp.ahk
Documentation: Included in the source code
I hope someone find this useful.