I realize there are a few different Winamp plugins out there that will do things similar to this. I've tried most of them and to me they were inadequate.
I'm posting this script because I really hope someone else finds it useful. I love AutoHotkey and I wanted to give back a little to the community. I use this script everyday on my work laptop. I'm not a programmer, but it works so I'm happy. I'm sure there are optimizations that could be done and please by all means post any tweaks or changes you think would be beneficial.
Here are a couple other things to note before I post the code:
-It does work whether or not you have Winamp set to minimize to the taskbar or to a systray icon.
-It's really intended to be used only for manually Locking/Unlocking your workstation. It doesn't work right if you have the ScreenSaver configured to "On resume, password protect" because the workstation doesn't actually enter a locked state until the ScreenSaver turns off.
-It's meant to run as a resident script in your AutoHotkey.ini. Although, I did test it as a stand alone script and it could be modified back to that state.
-I tried to put good, meaningful comments throughout to help people who want to take the code and make it their own.
-I give credits in my comments to 2 people from the AHK forums, "shimanov" & "deadprez". Both of whom had some good code that I used in creating my script. Many thanks to both of them!!!
And lastly, I give you Winamp Lock & Pause v0.6:
Here's the code to add into your AutoHotkey.ini
(assumes you have "winamp_Lock_Pause v0.6.ahk" in the AutoHotkey install dir)
;Launch Winamp_Lock_Pause as resident script #include %A_ScriptDir%\winamp_Lock_Pause v0.6.ahk Winamp_Lock_Pause()
Here is the main code, copy & paste to a text file "winamp_Lock_Pause v0.6.ahk"
; --------------------------------------------------------------- ; Winamp_Lock_Pause ; This script monitors LockWorkstation calls ; ; First checks to see if Winamp is running ; On Lock ; If Winamp is playing a song, pause playback ; Else If Winamp is paused, do nothing ; Else If Winamp is stopped, do nothing ; On Unlock ; If Winamp is paused, restart playback ; Else If Winamp is stopped, do nothing ; --------------------------------------------------------------- ; Largely created by MrInferno ; Last edited 2006-04-07 20:38 ; --------------------------------------------------------------- ; Based on script codes from "shimanov" ; Posted: Thu Sep 15, 2005 12:26 am ; Source: http://www.autohotkey.com/forum/viewtopic.php?t=5359 ; Posted: Tue Dec 06, 2005 9:14 pm ; Source: http://www.autohotkey.com/forum/viewtopic.php?t=6755 ; --------------------------------------------------------------- ;Initialize global constants WTS_SESSION_LOCK := 0x7 WTS_SESSION_UNLOCK := 0x8 NOTIFY_FOR_ALL_SESSIONS := 1 NOTIFY_FOR_THIS_SESSION := 0 WM_WTSSESSION_CHANGE := 0x02B1 Winamp_Lock_Pause( ) { Global WM_WTSSESSION_CHANGE Global NOTIFY_FOR_ALL_SESSION hw_ahk := FindWindowEx( 0, 0, "AutoHotkey", a_ScriptFullPath " - AutoHotkey v" a_AhkVersion ) OnMessage( WM_WTSSESSION_CHANGE, "Handle_WTSSESSION_CHANGE" ) success := DllCall( "wtsapi32.dll\WTSRegisterSessionNotification", "uint", hw_ahk, "uint", NOTIFY_FOR_ALL_SESSIONS ) if( ErrorLevel OR ! success ) { success := DllCall( "wtsapi32.dll\WTSUnRegisterSessionNotification", "uint", hw_ahk ) ;If DLL registration fails, wait 20 seconds and try again Sleep, 20000 Winamp_Lock_Pause( ) ;MsgBox, [WTSRegisterSessionNotification] failed: EL = %ErrorLevel% } return ;End Winamp_Lock_Pause } Handle_WTSSESSION_CHANGE( p_w, p_l, p_m, p_hw ) ; p_w = wParam ;Session state change event ; p_l = lParam ;Session ID ; p_m = Msg ;WM_WTSSESSION_CHANGE ; p_hw = hWnd ;Handle to Window { Global WTS_SESSION_LOCK Global WTS_SESSION_UNLOCK ;Is Winamp is running DetectHiddenWindows, On ;functions here work better with this option SetTitleMatchMode, 2 Process, Exist, Winamp.exe NewPID := ErrorLevel ;Errorlevel will be set to winamp.exe's PID (i.e. not blank or zero) if it's running If NewPID ;not blank or zero value { If ( p_w = WTS_SESSION_LOCK ) { Winamp_Pause( ) } Else If ( p_w = WTS_SESSION_UNLOCK ) { Winamp_Play( ) } } ;If Winamp isn't running, do nothing DetectHiddenWindows, Off } FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title ) { return, DllCall( "FindWindowEx", "uint", p_hw_parent, "uint", p_hw_child, "str", p_class, "str", p_title ) } ; --------------------------------------------------------------- ; Winamp_Pause ; Assumes already checked for Winamp process ; If Winamp is playing a song, pause playback ; Else If Winamp is paused, do nothing ; Else If Winamp is stopped, do nothing ; --------------------------------------------------------------- ; Largely created by MrInferno ; Last edited 2006-04-06 18:53 ; --------------------------------------------------------------- ; Based on script code from "deadprez" ; Posted: Tue Oct 04, 2005 2:28 pm ; Source: http://www.autohotkey.com/forum/viewtopic.php?t=5667 ; --------------------------------------------------------------- Winamp_Pause( ) { ;Initialize constants WM_USER = 0x0400 WM_COMMAND = 0x0111 IPC_ISPLAYING = 104 WINAMP_BUTTON3 = 40046 ;Pause button ;Is Winamp currently playing a song? SendMessage, WM_USER, 0, IPC_ISPLAYING,, ahk_class Winamp v1.x WinampStatus := ErrorLevel if (WinampStatus == 1) { ;Winamp is playing, pause playback SendMessage, WM_COMMAND, WINAMP_BUTTON3, WINAMP_BUTTON3,, ahk_class Winamp v1.x Return } else if (WinampStatus == 3 ) { ;Winamp is paused, do nothing Return } else { ;Winamp is stopped, do nothing Return } ;End Winamp_Pause } ; --------------------------------------------------------------- ; Winamp_Play ; Assumes already checked for Winamp process ; If Winamp is paused, restart playback ; Else If Winamp is stopped, do nothing ; --------------------------------------------------------------- ; Largely created by MrInferno ; Last edited 2006-04-06 18:53 ; --------------------------------------------------------------- ; Based on script code from "deadprez" ; Posted: Tue Oct 04, 2005 2:28 pm ; Source: http://www.autohotkey.com/forum/viewtopic.php?t=5667 ; --------------------------------------------------------------- Winamp_Play( ) { ;Initialize constants WM_USER = 0x0400 WM_COMMAND = 0x0111 IPC_ISPLAYING = 104 WINAMP_BUTTON3 = 40046 ;Pause button ;Is Winamp currently playing a song? SendMessage, WM_USER, 0, IPC_ISPLAYING,, ahk_class Winamp v1.x WinampStatus := ErrorLevel if (WinampStatus == 1) { ;Winamp is playing, do nothing Return } else if (WinampStatus == 3 ) { ;Winamp is paused, restart playback SendMessage, WM_COMMAND, WINAMP_BUTTON3, WINAMP_BUTTON3,, ahk_class Winamp v1.x Return } else { ;Winamp is stopped, do nothing Return } ;End Winamp_Play }