Hey, got the iTunes COM interface working with Dell Media buttons. This can rate your current track too, with #1, #2, etc. As far as I can tell, this works no matter what status iTunes is in - maximised/minimised/toolbar.
I'm assuming I'm doing things correctly with the WS - all that's required for this script is for ws4ahk.ahk to be included somewhere.
The only thing is that once AHK takes control of your volume buttons, they don't get passed through to your system (or to other programs). There's probably some code that could be added that sorts that though.
I still need to change the volume control to use COM, but that'll happen soon I expect.
Code:
#Include C:\Program Files\AutoHotKey\ws4ahk.ahk
; Necessary initialization
WS_Initialize("JScript")
itunes := WS_CreateObject("iTunes.Application")
WS_AddObject(itunes, "itunesapp")
WS_ReleaseObject(itunes)
; ############## iTunes ##############
;
; Media keys as normal.
;
; Rate current song:
; win+0 -> no stars
; win+1 -> *
; win+2 -> **
; win+3 -> ***
; win+4 -> ****
; win+5 -> *****
Media_Play_Pause::
WS_Exec("itunesapp.PlayPause()")
return
Media_Next::
WS_Exec("itunesapp.NextTrack()")
return
Media_Prev::
WS_Exec("itunesapp.PreviousTrack()")
return
Media_Stop::
WS_Exec("itunesapp.Stop()")
return
Volume_Mute::
;Toggles mute - I think this is really elegant. :)
WS_Exec("itunesapp.Mute ^= 1")
return
Volume_Down::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{down}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return
Volume_Up::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{up}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return
#0::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 0")
WS_ReleaseObject(currtrack)
return
#1::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 20")
WS_ReleaseObject(currtrack)
return
#2::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 40")
WS_ReleaseObject(currtrack)
return
#3::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 60")
WS_ReleaseObject(currtrack)
return
#4::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 80")
WS_ReleaseObject(currtrack)
return
#5::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 100")
WS_ReleaseObject(currtrack)
return
; Required cleanup
WS_Uninitialize()