; Media Keys AutoHotkey Script by Noah Coad, started in 2008, http://coad.net

; #=Win ^=Ctrl +=Shift !=Alt

; Volume Up & Down, Win+Alt+Up & Win+Alt+Down
#!Up::  send {Volume_Up}
#!Down::  send {Volume_Down}

; Media Pause/Play
; Win+. OR Win+Alt+. OR Win+Alt+Left OR Win+Alt+Space
#.:: 
#!.:: 
#!Left::
#!Space::
Media_Play_Pause::
	IfWinExist, iTunes ahk_class ITWindow
	{
		ControlSend ahk_parent, {shift}
		sleep 100
		ControlSend ahk_parent, ^{space}
	}
	else
	{
		Suspend On
		SendPlay {Media_Play_Pause}
		Suspend Off
	}
return

; Media Next, Win+/ OR Win+Alt+Right
#/::
#!Right::
Media_Next::
	IfWinExist, iTunes ahk_class ITWindow
	{
		ControlSend ahk_parent, {shift}
		sleep 100
		ControlSend ahk_parent, ^{right}
	}	
	else
	{
		Suspend On
		SendInput {Media_Next}
		Suspend Off
	}
return

; Media Previous, Win+,
#,::
Media_Prev::
	IfWinExist, iTunes ahk_class ITWindow
	{
		ControlSend ahk_parent, {shift}
		sleep 100
		ControlSend ahk_parent, ^{left}
	}	
	else
	{
		Suspend On
		SendInput {Media_Previous}
		Suspend Off
	}
return

; Rate the currently playing song 1 to 5 stars with Win+Alt+#
#!1:: Run powershell -command (itunes).CurrentTrack.Rating = 20,,Hide
#!2:: Run powershell -command (itunes).CurrentTrack.Rating = 40,,Hide
#!3:: Run powershell -command (itunes).CurrentTrack.Rating = 60,,Hide
#!4:: Run powershell -command (itunes).CurrentTrack.Rating = 80,,Hide
#!5:: Run powershell -command (itunes).CurrentTrack.Rating = 100,,Hide

; Play Music NOW, Win+Alt+P
#!p:: Run powershell -command (itPlaylist('PlayHotkey')).PlayFirstTrack(),,Hide

; Set media keyboard buttons
SC132:: SendInput {Media_Play_Pause}
Browser_Favorites::  SendInput {Media_Next}