From 7064418806801646570e47325ca88978a1186310 Mon Sep 17 00:00:00 2001 From: svn Date: Tue, 12 Jan 2010 22:32:59 +0000 Subject: [PATCH] Init AutoHotKey git-svn-id: svn://svn/src/AutoHotKey@856 4ca61c99-ecf1-0310-a92a-a4333d9a229c --- AutoHotkey.ahk | 20 ++ GmailKeys.ahk | 82 ++++++ Lib/COM.ahk | 623 ++++++++++++++++++++++++++++++++++++++++++++++ Lib/VA.ahk | 659 +++++++++++++++++++++++++++++++++++++++++++++++++ VolumeOSD.ahk | 107 ++++++++ Winamp.ahk | 85 +++++++ 6 files changed, 1576 insertions(+) create mode 100644 AutoHotkey.ahk create mode 100644 GmailKeys.ahk create mode 100644 Lib/COM.ahk create mode 100644 Lib/VA.ahk create mode 100644 VolumeOSD.ahk create mode 100644 Winamp.ahk diff --git a/AutoHotkey.ahk b/AutoHotkey.ahk new file mode 100644 index 0000000..ecf076c --- /dev/null +++ b/AutoHotkey.ahk @@ -0,0 +1,20 @@ +; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a +; semicolon, such as this one, are comments. They are not executed. + +; This script has a special filename and path because it is automatically +; launched when you run the program directly. Also, any text file whose +; name ends in .ahk is associated with the program, which means that it +; can be launched simply by double-clicking it. You can have as many .ahk +; files as you want, located in any folder. You can also run more than +; one ahk file simultaneously and each will get its own tray icon. + +;################# +;### NOTEPAD++ ### +; Control+Alt+N = Launch/activate Notepad++ +^!n:: +IfWinExist Notepad++ + WinActivate +else + Run C:\Program Files\Notepad++\notepad++.exe +return + diff --git a/GmailKeys.ahk b/GmailKeys.ahk new file mode 100644 index 0000000..901df85 --- /dev/null +++ b/GmailKeys.ahk @@ -0,0 +1,82 @@ +;******************************************************************************* +; Information +;******************************************************************************* +; AutoHotkey Version: 1.x +; Language: English +; Platform: XP/Vista/7 +; Author: Lowell Heddings (How-To Geek) +; URL: http://lifehacker.com/5175724/add-gmail-shortcuts-to-outlook-with-gmail-keys +; Real Author: Original script by Jayp: http://www.ocellated.com/2009/03/18/pimping-microsoft-outlook/ +; +; Script Function: Gmail Keys adds Gmail Shortcut Keys to Outlook +; +;******************************************************************************* +; Version History +;******************************************************************************* +; 0.1 release - initial set of hotkeys +;******************************************************************************* + + +#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. +SendMode Input ; Recommended for new scripts due to its superior speed and reliability. +;#NoTrayIcon +SendMode Input ; superior speed and reliability. +SetTitleMatchMode 2 ;allow partial match to window titles + + ;******************** + ;Hotkeys for Outlook + ;******************** + + ;As best I can tell, the window text 'NUIDocumentWindow' is not present + ;on any other items except the main window. Also, I look for the phrase + ; ' - Microsoft Outlook' in the title, which will not appear in the title (unless + ;a user types this string into the subject of a message or task). + #IfWinActive - Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow + e::HandleOutlookKeys("!.", "e") ;calls archive macro + f::HandleOutlookKeys("!w", "f") ;forwards message + r::HandleOutlookKeys("!r", "r") ;replies to message +; a::HandleOutlookKeys("^+r", "a") ;reply all + v::HandleOutlookKeys("^+v", "v") ;Move message box + +u::HandleOutlookKeys("^u", "+u") ;marks messages as unread + +i::HandleOutlookKeys("^q", "+i") ;marks messages as read + j::HandleOutlookKeys("!{Down}", "j") ;move down in list + +j::HandleOutlookKeys("+!{Down}", "+j") ;move down and select next item + k::HandleOutlookKeys("!{Up}", "k") ;move up + +k::HandleOutlookKeys("+!{Up}", "+k") ;move up and select next item + o::HandleOutlookKeys("^o", "o") ;open message + ;s::HandleOutlookKeys("{Insert}", "s") ;toggle flag (star) + c::HandleOutlookKeys("^n", "c") ;new message + /::HandleOutlookKeys("^e", "/") ;focus search box + .::HandleOutlookKeys("+{F10}", ".") ;Display context menu + #::HandleOutlookKeys("{Delete}", "#") ;delete message + ^g::HandleOutlookKeys("^y", "^g") ;goto folder + #IfWinActive + + ;Passes Outlook a special key combination for custom keystrokes or normal key value, depending on context + HandleOutlookKeys( specialKey, normalKey ) { + ;Activates key only on main outlook window, not messages, tasks, contacts, etc. + IfWinActive, - Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow, , + { + + ;Find out which control in Outlook has focus + ControlGetFocus, currentCtrl + ;MsgBox, Control with focus = %currentCtrl% + + ;set list of controls that should respond to specialKey. Controls are the list of emails and the main (and minor) controls of the reading pane, including controls when viewing certain attachments. + ;Currently I handle archiving when viewing attachments of Word, Excel, Powerpoint, Text, jpgs, pdfs + ;The control 'RichEdit20WPT1' (email subject line) is used extensively for inline editing. Thus it had to be removed. If an email's subject has focus, it won't archive... + ctrlList = Acrobat Preview Window1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,OlkPicturePreviewer1,paneClassDC1, RichEdit20WPT2,RichEdit20WPT4,RichEdit20WPT5,RICHEDIT50W1,SUPERGRID1,_WwG1 + + if currentCtrl in %ctrlList% + { + Send %specialKey% + ;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the folder pane.) + } else { + Send %normalKey% + } + + ;Allow typing normalKey in another window type within Outlook, like a mail message, task, appointment, etc. + } else { + Send %normalKey% + } + } diff --git a/Lib/COM.ahk b/Lib/COM.ahk new file mode 100644 index 0000000..0b9a477 --- /dev/null +++ b/Lib/COM.ahk @@ -0,0 +1,623 @@ +;------------------------------------------------------------------------------ +; COM.ahk Standard Library +; by Sean +; http://www.autohotkey.com/forum/topic22923.html +;------------------------------------------------------------------------------ + +COM_Init() +{ + Return DllCall("ole32\OleInitialize", "Uint", 0) +} + +COM_Term() +{ + Return DllCall("ole32\OleUninitialize") +} + +COM_VTable(ppv, idx) +{ + Return NumGet(NumGet(1*ppv)+4*idx) +} + +COM_QueryInterface(ppv, IID = "") +{ + If DllCall(NumGet(NumGet(1*ppv)+0), "Uint", ppv, "Uint", COM_GUID4String(IID,IID ? IID : IID=0 ? "{00000000-0000-0000-C000-000000000046}" : "{00020400-0000-0000-C000-000000000046}"), "UintP", ppv)=0 + Return ppv +} + +COM_AddRef(ppv) +{ + Return DllCall(NumGet(NumGet(1*ppv)+4), "Uint", ppv) +} + +COM_Release(ppv) +{ + Return DllCall(NumGet(NumGet(1*ppv)+8), "Uint", ppv) +} + +COM_QueryService(ppv, SID, IID = "") +{ + DllCall(NumGet(NumGet(1*ppv)+4*0), "Uint", ppv, "Uint", COM_GUID4String(IID_IServiceProvider,"{6D5140C1-7436-11CE-8034-00AA006009FA}"), "UintP", psp) + DllCall(NumGet(NumGet(1*psp)+4*3), "Uint", psp, "Uint", COM_GUID4String(SID,SID), "Uint", IID ? COM_GUID4String(IID,IID) : &SID, "UintP", ppv:=0) + DllCall(NumGet(NumGet(1*psp)+4*2), "Uint", psp) + Return ppv +} + +COM_FindConnectionPoint(pdp, DIID) +{ + DllCall(NumGet(NumGet(1*pdp)+ 0), "Uint", pdp, "Uint", COM_GUID4String(IID_IConnectionPointContainer, "{B196B284-BAB4-101A-B69C-00AA00341D07}"), "UintP", pcc) + DllCall(NumGet(NumGet(1*pcc)+16), "Uint", pcc, "Uint", COM_GUID4String(DIID,DIID), "UintP", pcp) + DllCall(NumGet(NumGet(1*pcc)+ 8), "Uint", pcc) + Return pcp +} + +COM_GetConnectionInterface(pcp) +{ + VarSetCapacity(DIID, 16, 0) + DllCall(NumGet(NumGet(1*pcp)+12), "Uint", pcp, "Uint", &DIID) + Return COM_String4GUID(&DIID) +} + +COM_Advise(pcp, psink) +{ + DllCall(NumGet(NumGet(1*pcp)+20), "Uint", pcp, "Uint", psink, "UintP", nCookie) + Return nCookie +} + +COM_Unadvise(pcp, nCookie) +{ + Return DllCall(NumGet(NumGet(1*pcp)+24), "Uint", pcp, "Uint", nCookie) +} + +COM_Enumerate(penum, ByRef Result, ByRef vt = "") +{ + VarSetCapacity(varResult,16,0) + If (0 = hr:=DllCall(NumGet(NumGet(1*penum)+12), "Uint", penum, "Uint", 1, "Uint", &varResult, "UintP", 0)) + Result:=(vt:=NumGet(varResult,0,"Ushort"))=8||vt<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . COM_SysFreeString(bstr) : NumGet(varResult,8) + Return hr +} + +COM_Invoke(pdsp,name="",prm0="vT_NoNe",prm1="vT_NoNe",prm2="vT_NoNe",prm3="vT_NoNe",prm4="vT_NoNe",prm5="vT_NoNe",prm6="vT_NoNe",prm7="vT_NoNe",prm8="vT_NoNe",prm9="vT_NoNe") +{ + If name= + Return COM_Release(pdsp) + If name contains . + { + SubStr(name,1,1)!="." ? name.=".":name:=SubStr(name,2) . ".",COM_AddRef(pdsp) + Loop, Parse, name, . + { + If A_Index=1 + { + name := A_LoopField + Continue + } + Else If name not contains [,( + prmn := "" + Else If InStr("])",SubStr(name,0)) + Loop, Parse, name, [(,'")] + If A_Index=1 + name := A_LoopField + Else prmn := A_LoopField + Else + { + name .= "." . A_LoopField + Continue + } + If A_LoopField!= + pdsp:= COM_Invoke(pdsp,name,prmn!="" ? prmn:"vT_NoNe")+COM_Release(pdsp)*0,name:=A_LoopField + Else Return prmn!="" ? COM_Invoke(pdsp,name,prmn,prm0,prm1,prm2,prm3,prm4,prm5,prm6,prm7,prm8):COM_Invoke(pdsp,name,prm0,prm1,prm2,prm3,prm4,prm5,prm6,prm7,prm8,prm9),COM_Release(pdsp) + } + } + sParams := "0123456789" + Loop, Parse, sParams + If (prm%A_LoopField% == "vT_NoNe") + { + sParams := SubStr(sParams,1,A_Index-1) + Break + } + VarSetCapacity(varg,16*nParams:=StrLen(sParams),0), VarSetCapacity(DispParams,16,0), VarSetCapacity(varResult,32,0), VarSetCapacity(ExcepInfo,32,0) + Loop, Parse, sParams +; If prm%A_LoopField%+0=="" || InStr(prm%A_LoopField%,".") || prm%A_LoopField%>=0x80000000 || prm%A_LoopField%<-0x80000000 + If prm%A_LoopField% is not integer + NumPut(COM_SysAllocString(prm%A_LoopField%),NumPut(8,varg,(nParams-A_Index)*16),4) + Else NumPut(SubStr(prm%A_LoopField%,1,1)="+" ? 9:prm%A_LoopField%=="-0" ? (prm%A_LoopField%:=0x80020004)*0+10:3,NumPut(prm%A_LoopField%,varg,(nParams-A_Index)*16+8),-12,"Ushort") + If nParams + NumPut(nParams,NumPut(&varg,DispParams),4) + If (nvk := SubStr(name,0)="=" ? 12:3)=12 + name := SubStr(name,1,-1),NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4) + Global COM_HR, COM_LR:="" + If (COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+20),"Uint",pdsp,"Uint",&varResult+16,"UintP",COM_Unicode4Ansi(wname,name),"Uint",1,"Uint",LCID,"intP",dispID,"Uint"))=0&&(COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",nvk,"Uint",&DispParams,"Uint",&varResult,"Uint",&ExcepInfo,"Uint",0,"Uint"))!=0&&nParams&&nvk!=12&&(COM_LR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",12,"Uint",NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4)-16,"Uint",0,"Uint",0,"Uint",0,"Uint"))=0 + COM_HR:=0 + Loop, % nParams + NumGet(varg,(A_Index-1)*16,"Ushort")=8 ? COM_SysFreeString(NumGet(varg,(A_Index-1)*16+8)) : "" + Global COM_VT := NumGet(varResult,0,"Ushort") + Return COM_HR=0 ? COM_VT>1 ? COM_VT=8||COM_VT<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . COM_SysFreeString(bstr):NumGet(varResult,8):"":COM_Error(COM_HR,COM_LR,&ExcepInfo,name) +} + +COM_Invoke_(pdsp,name,typ0="",prm0="",typ1="",prm1="",typ2="",prm2="",typ3="",prm3="",typ4="",prm4="",typ5="",prm5="",typ6="",prm6="",typ7="",prm7="",typ8="",prm8="",typ9="",prm9="") +{ + If name contains . + { + SubStr(name,1,1)!="." ? name.=".":name:=SubStr(name,2) . ".", COM_AddRef(pdsp) + Loop, Parse, name, . + { + If A_Index=1 + { + name := A_LoopField + Continue + } + Else If name not contains [,( + prmn := "" + Else If InStr("])",SubStr(name,0)) + Loop, Parse, name, [(,'")] + If A_Index=1 + name := A_LoopField + Else prmn := A_LoopField + Else + { + name .= "." . A_LoopField + Continue + } + If A_LoopField!= + pdsp:= COM_Invoke(pdsp,name,prmn!="" ? prmn:"vT_NoNe")+COM_Release(pdsp)*0,name:=A_LoopField + Else Return COM_Invoke_(pdsp,name,typ0,prm0,typ1,prm1,typ2,prm2,typ3,prm3,typ4,prm4,typ5,prm5,typ6,prm6,typ7,prm7,typ8,prm8,typ9,prm9),COM_Release(pdsp) + } + } + sParams := "0123456789" + Loop, Parse, sParams + If (typ%A_LoopField% = "") + { + sParams := SubStr(sParams,1,A_Index-1) + Break + } + VarSetCapacity(varg,16*nParams:=StrLen(sParams),0), VarSetCapacity(DispParams,16,0), VarSetCapacity(varResult,32,0), VarSetCapacity(ExcepInfo,32,0) + Loop, Parse, sParams + NumPut(typ%A_LoopField%,varg,(nParams-A_Index)*16,"Ushort"),typ%A_LoopField%&0x4000=0 ? NumPut(typ%A_LoopField%=8 ? COM_SysAllocString(prm%A_LoopField%):prm%A_LoopField%,varg,(nParams-A_Index)*16+8,typ%A_LoopField%=5||typ%A_LoopField%=7 ? "double":typ%A_LoopField%=4 ? "float":"int64"):typ%A_LoopField%=0x400C||typ%A_LoopField%=0x400E ? NumPut(prm%A_LoopField%,varg,(nParams-A_Index)*16+8):(VarSetCapacity(_ref_%A_LoopField%,8,0),NumPut(&_ref_%A_LoopField%,varg,(nParams-A_Index)*16+8),NumPut((prmx:=prm%A_LoopField%)&&typ%A_LoopField%=0x4008 ? COM_SysAllocString(%prmx%):%prmx%,_ref_%A_LoopField%,0,typ%A_LoopField%=0x4005||typ%A_LoopField%=0x4007 ? "double":typ%A_LoopField%=0x4004 ? "float":"int64")) + If nParams + NumPut(nParams,NumPut(&varg,DispParams),4) + If (nvk := SubStr(name,0)="=" ? 12:3)=12 + name := SubStr(name,1,-1),NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4) + Global COM_HR, COM_LR:="" + If (COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+20),"Uint",pdsp,"Uint",&varResult+16,"UintP",COM_Unicode4Ansi(wname,name),"Uint",1,"Uint",LCID,"intP",dispID,"Uint"))=0&&(COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",nvk,"Uint",&DispParams,"Uint",&varResult,"Uint",&ExcepInfo,"Uint",0,"Uint"))!=0&&nParams&&nvk!=12&&(COM_LR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",12,"Uint",NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4)-16,"Uint",0,"Uint",0,"Uint",0,"Uint"))=0 + COM_HR:=0 + Loop, Parse, sParams + typ%A_LoopField%&0x4000=0 ? (typ%A_LoopField%=8 ? COM_SysFreeString(NumGet(varg,(nParams-A_Index)*16+8)):""):typ%A_LoopField%=0x400C||typ%A_LoopField%=0x400E ? "":(prmx:=prm%A_LoopField%,%prmx%:=typ%A_LoopField%=0x4008 ? COM_Ansi4Unicode(prmx:=NumGet(_ref_%A_LoopField%)) . COM_SysFreeString(prmx):NumGet(_ref_%A_LoopField%,0,typ%A_LoopField%=0x4005||typ%A_LoopField%=0x4007 ? "double":typ%A_LoopField%=0x4004 ? "float":"int64")) + Global COM_VT := NumGet(varResult,0,"Ushort") + Return COM_HR=0 ? COM_VT>1 ? COM_VT=8||COM_VT<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . COM_SysFreeString(bstr):NumGet(varResult,8):"":COM_Error(COM_HR,COM_LR,&ExcepInfo,name) +} + +COM_DispInterface(this, prm1="", prm2="", prm3="", prm4="", prm5="", prm6="", prm7="", prm8="") +{ + Critical + If A_EventInfo = 6 + hr:=DllCall(NumGet(NumGet(0+p:=NumGet(this+8))+28),"Uint",p,"Uint",prm1,"UintP",pname,"Uint",1,"UintP",0), hr==0 ? (VarSetCapacity(sfn,63),DllCall("user32\wsprintfA","str",sfn,"str","%s%S","Uint",this+40,"Uint",pname,"Cdecl"),COM_SysFreeString(pname),%sfn%(prm5,this,prm6)):"" + Else If A_EventInfo = 5 + hr:=DllCall(NumGet(NumGet(0+p:=NumGet(this+8))+40),"Uint",p,"Uint",prm2,"Uint",prm3,"Uint",prm5) + Else If A_EventInfo = 4 + NumPut(0*hr:=0x80004001,prm3+0) + Else If A_EventInfo = 3 + NumPut(0,prm1+0) + Else If A_EventInfo = 2 + NumPut(hr:=NumGet(this+4)-1,this+4) + Else If A_EventInfo = 1 + NumPut(hr:=NumGet(this+4)+1,this+4) + Else If A_EventInfo = 0 + COM_IsEqualGUID(this+24,prm1)||InStr("{00020400-0000-0000-C000-000000000046}{00000000-0000-0000-C000-000000000046}",COM_String4GUID(prm1)) ? NumPut(NumPut(NumGet(this+4)+1,this+4)-8,prm2+0):NumPut(0*hr:=0x80004002,prm2+0) + Return hr +} + +COM_DispGetParam(pDispParams, Position = 0, vt = 8) +{ + VarSetCapacity(varResult,16,0) + DllCall("oleaut32\DispGetParam", "Uint", pDispParams, "Uint", Position, "Ushort", vt, "Uint", &varResult, "UintP", nArgErr) + Return NumGet(varResult,0,"Ushort")=8 ? COM_Ansi4Unicode(NumGet(varResult,8)) . COM_SysFreeString(NumGet(varResult,8)) : NumGet(varResult,8) +} + +COM_DispSetParam(val, pDispParams, Position = 0, vt = 8) +{ + Return NumPut(vt=8 ? COM_SysAllocString(val) : val,NumGet(NumGet(pDispParams+0)+(NumGet(pDispParams+8)-Position)*16-8),0,vt=11||vt=2 ? "short" : "int") +} + +COM_Error(hr = "", lr = "", pei = "", name = "") +{ + Static bDebug:=1 + If Not pei + { + bDebug:=hr + Global COM_HR, COM_LR + Return COM_HR&&COM_LR ? COM_LR<<32|COM_HR:COM_HR + } + Else If !bDebug + Return + hr ? (VarSetCapacity(sError,1023),VarSetCapacity(nError,10),DllCall("kernel32\FormatMessageA","Uint",0x1000,"Uint",0,"Uint",hr<>0x80020009 ? hr : (bExcep:=1)*(hr:=NumGet(pei+28)) ? hr : hr:=NumGet(pei+0,0,"Ushort")+0x80040200,"Uint",0,"str",sError,"Uint",1024,"Uint",0),DllCall("user32\wsprintfA","str",nError,"str","0x%08X","Uint",hr,"Cdecl")) : sError:="The COM Object may not be a valid Dispatch Object!`n`tFirst ensure that COM Library has been initialized through COM_Init().`n", lr ? (VarSetCapacity(sError2,1023),VarSetCapacity(nError2,10),DllCall("kernel32\FormatMessageA","Uint",0x1000,"Uint",0,"Uint",lr,"Uint",0,"str",sError2,"Uint",1024,"Uint",0),DllCall("user32\wsprintfA","str",nError2,"str","0x%08X","Uint",lr,"Cdecl")) : "" + MsgBox, 260, COM Error Notification, % "Function Name:`t""" . name . """`nERROR:`t" . sError . "`t(" . nError . ")" . (bExcep ? SubStr(NumGet(pei+24) ? DllCall(NumGet(pei+24),"Uint",pei) : "",1,0) . "`nPROG:`t" . COM_Ansi4Unicode(NumGet(pei+4)) . COM_SysFreeString(NumGet(pei+4)) . "`nDESC:`t" . COM_Ansi4Unicode(NumGet(pei+8)) . COM_SysFreeString(NumGet(pei+8)) . "`nHELP:`t" . COM_Ansi4Unicode(NumGet(pei+12)) . COM_SysFreeString(NumGet(pei+12)) . "," . NumGet(pei+16) : "") . (lr ? "`n`nERROR2:`t" . sError2 . "`t(" . nError2 . ")" : "") . "`n`nWill Continue?" + IfMsgBox, No, Exit +} + +COM_CreateIDispatch() +{ + Static IDispatch + If Not VarSetCapacity(IDispatch) + { + VarSetCapacity(IDispatch,28,0), nParams=3112469 + Loop, Parse, nParams + NumPut(RegisterCallback("COM_DispInterface","",A_LoopField,A_Index-1),IDispatch,4*(A_Index-1)) + } + Return &IDispatch +} + +COM_GetDefaultInterface(pdisp, LCID = 0) +{ + DllCall(NumGet(NumGet(1*pdisp) +12), "Uint", pdisp , "UintP", ctinf) + If ctinf + { + DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint" , 0, "Uint", LCID, "UintP", ptinf) + DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr) + DllCall(NumGet(NumGet(1*pdisp)+ 0), "Uint", pdisp, "Uint" , pattr, "UintP", ppv) + DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr) + DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf) + If ppv + DllCall(NumGet(NumGet(1*pdisp)+ 8), "Uint", pdisp), pdisp := ppv + } + Return pdisp +} + +COM_GetDefaultEvents(pdisp, LCID = 0) +{ + DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint" , 0, "Uint", LCID, "UintP", ptinf) + DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr) + VarSetCapacity(IID,16), DllCall("RtlMoveMemory", "Uint", &IID, "Uint", pattr, "Uint", 16) + DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr) + DllCall(NumGet(NumGet(1*ptinf)+72), "Uint", ptinf, "UintP", ptlib, "UintP", idx) + DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf) + Loop, % DllCall(NumGet(NumGet(1*ptlib)+12), "Uint", ptlib) + { + DllCall(NumGet(NumGet(1*ptlib)+20), "Uint", ptlib, "Uint", A_Index-1, "UintP", TKind) + If TKind <> 5 + Continue + DllCall(NumGet(NumGet(1*ptlib)+16), "Uint", ptlib, "Uint", A_Index-1, "UintP", ptinf) + DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr) + nCount:=NumGet(pattr+48,0,"Ushort") + DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr) + Loop, % nCount + { + DllCall(NumGet(NumGet(1*ptinf)+36), "Uint", ptinf, "Uint", A_Index-1, "UintP", nFlags) + If !(nFlags & 1) + Continue + DllCall(NumGet(NumGet(1*ptinf)+32), "Uint", ptinf, "Uint", A_Index-1, "UintP", hRefType) + DllCall(NumGet(NumGet(1*ptinf)+56), "Uint", ptinf, "Uint", hRefType , "UintP", prinf) + DllCall(NumGet(NumGet(1*prinf)+12), "Uint", prinf, "UintP", pattr) + nFlags & 2 ? DIID:=COM_String4GUID(pattr) : bFind:=COM_IsEqualGUID(pattr,&IID) + DllCall(NumGet(NumGet(1*prinf)+76), "Uint", prinf, "Uint" , pattr) + DllCall(NumGet(NumGet(1*prinf)+ 8), "Uint", prinf) + } + DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf) + If bFind + Break + } + DllCall(NumGet(NumGet(1*ptlib)+ 8), "Uint", ptlib) + Return bFind ? DIID : "{00000000-0000-0000-0000-000000000000}" +} + +COM_GetGuidOfName(pdisp, Name, LCID = 0) +{ + DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint", 0, "Uint", LCID, "UintP", ptinf) + DllCall(NumGet(NumGet(1*ptinf)+72), "Uint", ptinf, "UintP", ptlib, "UintP", idx) + DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf), ptinf:=0 + DllCall(NumGet(NumGet(1*ptlib)+44), "Uint", ptlib, "Uint", COM_Unicode4Ansi(Name,Name), "Uint", 0, "UintP", ptinf, "UintP", memID, "UshortP", 1) + DllCall(NumGet(NumGet(1*ptlib)+ 8), "Uint", ptlib) + DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr) + GUID := COM_String4GUID(pattr) + DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr) + DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf) + Return GUID +} + +COM_GetTypeInfoOfGuid(pdisp, GUID, LCID = 0) +{ + DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint", 0, "Uint", LCID, "UintP", ptinf) + DllCall(NumGet(NumGet(1*ptinf)+72), "Uint", ptinf, "UintP", ptlib, "UintP", idx) + DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf), ptinf := 0 + DllCall(NumGet(NumGet(1*ptlib)+24), "Uint", ptlib, "Uint", COM_GUID4String(GUID,GUID), "UintP", ptinf) + DllCall(NumGet(NumGet(1*ptlib)+ 8), "Uint", ptlib) + Return ptinf +} + +; A Function Name including Prefix is limited to 63 bytes! +COM_ConnectObject(psource, prefix = "", DIID = "") +{ + If Not DIID + 0+(pconn:=COM_FindConnectionPoint(psource,"{00020400-0000-0000-C000-000000000046}")) ? (DIID:=COM_GetConnectionInterface(pconn))="{00020400-0000-0000-C000-000000000046}" ? DIID:=COM_GetDefaultEvents(psource) : "" : pconn:=COM_FindConnectionPoint(psource,DIID:=COM_GetDefaultEvents(psource)) + Else pconn:=COM_FindConnectionPoint(psource,SubStr(DIID,1,1)="{" ? DIID : DIID:=COM_GetGuidOfName(psource,DIID)) + If !pconn || !ptinf:=COM_GetTypeInfoOfGuid(psource,DIID) + { + MsgBox, No Event Interface Exists! + Return + } + psink:=COM_CoTaskMemAlloc(40+StrLen(prefix)+1), NumPut(1,NumPut(COM_CreateIDispatch(),psink+0)), NumPut(psource,NumPut(ptinf,psink+8)) + DllCall("RtlMoveMemory", "Uint", psink+24, "Uint", COM_GUID4String(DIID,DIID), "Uint", 16) + DllCall("RtlMoveMemory", "Uint", psink+40, "Uint", &prefix, "Uint", StrLen(prefix)+1) + NumPut(COM_Advise(pconn,psink),NumPut(pconn,psink+16)) + Return psink +} + +COM_DisconnectObject(psink) +{ + Return COM_Unadvise(NumGet(psink+16),NumGet(psink+20))=0 ? (0,COM_Release(NumGet(psink+16)),COM_Release(NumGet(psink+8)),COM_CoTaskMemFree(psink)) : 1 +} + +COM_CreateObject(CLSID, IID = "", CLSCTX = 5) +{ + DllCall("ole32\CoCreateInstance", "Uint", SubStr(CLSID,1,1)="{" ? COM_GUID4String(CLSID,CLSID) : COM_CLSID4ProgID(CLSID,CLSID), "Uint", 0, "Uint", CLSCTX, "Uint", COM_GUID4String(IID,IID ? IID : IID=0 ? "{00000000-0000-0000-C000-000000000046}" : "{00020400-0000-0000-C000-000000000046}"), "UintP", ppv) + Return ppv +} + +COM_ActiveXObject(ProgID) +{ + DllCall("ole32\CoCreateInstance", "Uint", SubStr(ProgID,1,1)="{" ? COM_GUID4String(ProgID,ProgID) : COM_CLSID4ProgID(ProgID,ProgID), "Uint", 0, "Uint", 5, "Uint", COM_GUID4String(IID_IDispatch,"{00020400-0000-0000-C000-000000000046}"), "UintP", pdisp) + Return COM_GetDefaultInterface(pdisp) +} + +COM_GetObject(Moniker) +{ + DllCall("ole32\CoGetObject", "Uint", COM_Unicode4Ansi(Moniker,Moniker), "Uint", 0, "Uint", COM_GUID4String(IID_IDispatch,"{00020400-0000-0000-C000-000000000046}"), "UintP", pdisp) + Return COM_GetDefaultInterface(pdisp) +} + +COM_GetActiveObject(ProgID) +{ + DllCall("oleaut32\GetActiveObject", "Uint", SubStr(ProgID,1,1)="{" ? COM_GUID4String(ProgID,ProgID) : COM_CLSID4ProgID(ProgID,ProgID), "Uint", 0, "UintP", punk) + DllCall(NumGet(NumGet(1*punk)+0), "Uint", punk, "Uint", COM_GUID4String(IID_IDispatch,"{00020400-0000-0000-C000-000000000046}"), "UintP", pdisp) + DllCall(NumGet(NumGet(1*punk)+8), "Uint", punk) + Return COM_GetDefaultInterface(pdisp) +} + +COM_CLSID4ProgID(ByRef CLSID, ProgID) +{ + VarSetCapacity(CLSID, 16) + DllCall("ole32\CLSIDFromProgID", "Uint", COM_Unicode4Ansi(ProgID,ProgID), "Uint", &CLSID) + Return &CLSID +} + +COM_GUID4String(ByRef CLSID, String) +{ + VarSetCapacity(CLSID, 16) + DllCall("ole32\CLSIDFromString", "Uint", COM_Unicode4Ansi(String,String,38), "Uint", &CLSID) + Return &CLSID +} + +COM_ProgID4CLSID(pCLSID) +{ + DllCall("ole32\ProgIDFromCLSID", "Uint", pCLSID, "UintP", pProgID) + Return COM_Ansi4Unicode(pProgID) . COM_CoTaskMemFree(pProgID) +} + +COM_String4GUID(pGUID) +{ + VarSetCapacity(String, 38 * 2 + 1) + DllCall("ole32\StringFromGUID2", "Uint", pGUID, "Uint", &String, "int", 39) + Return COM_Ansi4Unicode(&String, 38) +} + +COM_IsEqualGUID(pGUID1, pGUID2) +{ + Return DllCall("ole32\IsEqualGUID", "Uint", pGUID1, "Uint", pGUID2) +} + +COM_CoCreateGuid() +{ + VarSetCapacity(GUID, 16, 0) + DllCall("ole32\CoCreateGuid", "Uint", &GUID) + Return COM_String4GUID(&GUID) +} + +COM_CoTaskMemAlloc(cb) +{ + Return DllCall("ole32\CoTaskMemAlloc", "Uint", cb) +} + +COM_CoTaskMemFree(pv) +{ + DllCall("ole32\CoTaskMemFree", "Uint", pv) +} + +COM_CoInitialize() +{ + Return DllCall("ole32\CoInitialize", "Uint", 0) +} + +COM_CoUninitialize() +{ + DllCall("ole32\CoUninitialize") +} + +COM_SysAllocString(sString) +{ + Return DllCall("oleaut32\SysAllocString", "Uint", COM_Ansi2Unicode(sString,wString)) +} + +COM_SysFreeString(bstr) +{ + DllCall("oleaut32\SysFreeString", "Uint", bstr) +} + +COM_SysStringLen(bstr) +{ + Return DllCall("oleaut32\SysStringLen", "Uint", bstr) +} + +COM_SafeArrayDestroy(psa) +{ + Return DllCall("oleaut32\SafeArrayDestroy", "Uint", psa) +} + +COM_VariantClear(pvarg) +{ + Return DllCall("oleaut32\VariantClear", "Uint", pvarg) +} + +COM_AccInit() +{ + COM_Init() + If Not DllCall("GetModuleHandle", "str", "oleacc") + Return DllCall("LoadLibrary", "str", "oleacc") +} + +COM_AccTerm() +{ + COM_Term() + If h:= DllCall("GetModuleHandle", "str", "oleacc") + Return DllCall("FreeLibrary", "Uint", h) +} + +COM_AccessibleChildren(pacc, cChildren, ByRef varChildren) +{ + VarSetCapacity(varChildren,cChildren*16,0) + If DllCall("oleacc\AccessibleChildren", "Uint", pacc, "Uint", 0, "Uint", cChildren+0, "Uint", &varChildren, "UintP", cChildren:=0)=0 + Return cChildren +} + +COM_AccessibleObjectFromEvent(hWnd, idObject, idChild, ByRef _idChild_="") +{ + VarSetCapacity(varChild,16,0) + If DllCall("oleacc\AccessibleObjectFromEvent", "Uint", hWnd, "Uint", idObject, "Uint", idChild, "UintP", pacc, "Uint", &varChild)=0 + Return pacc, _idChild_:=NumGet(varChild,8) +} + +COM_AccessibleObjectFromPoint(x, y, ByRef _idChild_="") +{ + VarSetCapacity(varChild,16,0) + If DllCall("oleacc\AccessibleObjectFromPoint", "int", x, "int", y, "UintP", pacc, "Uint", &varChild)=0 + Return pacc, _idChild_:=NumGet(varChild,8) +} + +COM_AccessibleObjectFromWindow(hWnd, idObject=-4, IID = "") +{ + If DllCall("oleacc\AccessibleObjectFromWindow", "Uint", hWnd, "Uint", idObject, "Uint", COM_GUID4String(IID, IID ? IID : idObject&0xFFFFFFFF==0xFFFFFFF0 ? "{00020400-0000-0000-C000-000000000046}":"{618736E0-3C3D-11CF-810C-00AA00389B71}"), "UintP", pacc)=0 + Return pacc +} + +COM_WindowFromAccessibleObject(pacc) +{ + If DllCall("oleacc\WindowFromAccessibleObject", "Uint", pacc, "UintP", hWnd)=0 + Return hWnd +} + +COM_GetRoleText(nRole) +{ + nSize:= DllCall("oleacc\GetRoleTextA", "Uint", nRole, "Uint", 0, "Uint", 0) + VarSetCapacity(sRole,nSize) + If DllCall("oleacc\GetRoleTextA", "Uint", nRole, "str", sRole, "Uint", nSize+1) + Return sRole +} + +COM_GetStateText(nState) +{ + nSize:= DllCall("oleacc\GetStateTextA", "Uint", nState, "Uint", 0, "Uint", 0) + VarSetCapacity(sState,nSize) + If DllCall("oleacc\GetStateTextA", "Uint", nState, "str", sState, "Uint", nSize+1) + Return sState +} + +COM_AtlAxWinInit(Version = "") +{ + COM_Init() + If Not DllCall("GetModuleHandle", "str", "atl" . Version) + DllCall("LoadLibrary", "str", "atl" . Version) + Return DllCall("atl" . Version . "\AtlAxWinInit") +} + +COM_AtlAxWinTerm(Version = "") +{ + COM_Term() + If h:= DllCall("GetModuleHandle", "str", "atl" . Version) + Return DllCall("FreeLibrary", "Uint", h) +} + +COM_AtlAxAttachControl(pdsp, hWnd, Version = "") +{ + Return DllCall("atl" . Version . "\AtlAxAttachControl", "Uint", punk:=COM_QueryInterface(pdsp,0), "Uint", hWnd, "Uint", 0), COM_Release(punk) +} + +COM_AtlAxCreateControl(hWnd, Name, Version = "") +{ + If DllCall("atl" . Version . "\AtlAxCreateControl", "Uint", COM_Unicode4Ansi(Name,Name), "Uint", hWnd, "Uint", 0, "Uint", 0)=0 + Return COM_AtlAxGetControl(hWnd, Version) +} + +COM_AtlAxGetControl(hWnd, Version = "") +{ + If DllCall("atl" . Version . "\AtlAxGetControl", "Uint", hWnd, "UintP", punk)=0 + pdsp:=COM_QueryInterface(punk), COM_Release(punk) + Return pdsp +} + +COM_AtlAxGetHost(hWnd, Version = "") +{ + If DllCall("atl" . Version . "\AtlAxGetHost", "Uint", hWnd, "UintP", punk)=0 + pdsp:=COM_QueryInterface(punk), COM_Release(punk) + Return pdsp +} + +COM_AtlAxCreateContainer(hWnd, l, t, w, h, Name = "", Version = "") +{ + Return DllCall("CreateWindowEx", "Uint",0x200, "str", "AtlAxWin" . Version, "Uint", Name ? &Name : 0, "Uint", 0x54000000, "int", l, "int", t, "int", w, "int", h, "Uint", hWnd, "Uint", 0, "Uint", 0, "Uint", 0) +} + +COM_AtlAxGetContainer(pdsp, bCtrl = "") +{ + DllCall(NumGet(NumGet(1*pdsp)+ 0), "Uint", pdsp, "Uint", COM_GUID4String(IID_IOleWindow,"{00000114-0000-0000-C000-000000000046}"), "UintP", pwin) + DllCall(NumGet(NumGet(1*pwin)+12), "Uint", pwin, "UintP", hCtrl) + DllCall(NumGet(NumGet(1*pwin)+ 8), "Uint", pwin) + Return bCtrl ? hCtrl : DllCall("GetParent", "Uint", hCtrl) +} + +COM_Ansi4Unicode(pString, nSize = "") +{ + If (nSize = "") + nSize:=DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0) + VarSetCapacity(sString, nSize) + DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize + 1, "Uint", 0, "Uint", 0) + Return sString +} + +COM_Unicode4Ansi(ByRef wString, sString, nSize = "") +{ + If (nSize = "") + nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0) + VarSetCapacity(wString, nSize * 2 + 1) + DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize + 1) + Return &wString +} + +COM_Ansi2Unicode(ByRef sString, ByRef wString, nSize = "") +{ + If (nSize = "") + nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0) + VarSetCapacity(wString, nSize * 2 + 1) + DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize + 1) + Return &wString +} + +COM_Unicode2Ansi(ByRef wString, ByRef sString, nSize = "") +{ + pString := wString + 0 > 65535 ? wString : &wString + If (nSize = "") + nSize:=DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0) + VarSetCapacity(sString, nSize) + DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize + 1, "Uint", 0, "Uint", 0) + Return &sString +} + +COM_ScriptControl(sCode, sLang = "", bEval = False, sFunc = "", sName = "", pdisp = 0, bGlobal = False) +{ + COM_Init() + psc := COM_CreateObject("MSScriptControl.ScriptControl") + COM_Invoke(psc, "Language", sLang ? sLang : "VBScript") + sName ? COM_Invoke(psc, "AddObject", sName, "+" . pdisp, bGlobal) : "" + sFunc ? COM_Invoke(psc, "AddCode", sCode) : "" + ret := COM_Invoke(psc, bEval ? "Eval" : "ExecuteStatement", sFunc ? sFunc : sCode) + COM_Release(psc) + COM_Term() + Return ret +} diff --git a/Lib/VA.ahk b/Lib/VA.ahk new file mode 100644 index 0000000..e3c8f8f --- /dev/null +++ b/Lib/VA.ahk @@ -0,0 +1,659 @@ +; +; MASTER CONTROLS +; + +VA_GetMasterVolume(channel="", device_desc="playback") +{ + aev := VA_GetAudioEndpointVolume(device_desc) + if channel = + VA_IAudioEndpointVolume_GetMasterVolumeLevelScalar(aev, vol) + else + VA_IAudioEndpointVolume_GetChannelVolumeLevelScalar(aev, channel-1, vol) + COM_Release(aev) + return vol*100 +} + +VA_SetMasterVolume(vol, channel="", device_desc="playback") +{ + vol := vol>100 ? 100 : vol<0 ? 0 : vol + aev := VA_GetAudioEndpointVolume(device_desc) + if channel = + VA_IAudioEndpointVolume_SetMasterVolumeLevelScalar(aev, vol/100) + else + VA_IAudioEndpointVolume_SetChannelVolumeLevelScalar(aev, channel-1, vol/100) + COM_Release(aev) +} + +VA_GetMasterChannelCount(device_desc="playback") +{ + aev := VA_GetAudioEndpointVolume(device_desc) + VA_IAudioEndpointVolume_GetChannelCount(aev, count) + COM_Release(aev) + return count +} + +VA_SetMasterMute(mute, device_desc="playback") +{ + aev := VA_GetAudioEndpointVolume(device_desc) + VA_IAudioEndpointVolume_SetMute(aev, mute) + COM_Release(aev) +} + +VA_GetMasterMute(device_desc="playback") +{ + aev := VA_GetAudioEndpointVolume(device_desc) + VA_IAudioEndpointVolume_GetMute(aev, mute) + COM_Release(aev) + return mute +} + +; +; SUBUNIT CONTROLS +; + +VA_GetVolume(subunit_desc="1", channel="", device_desc="playback") +{ + avl := VA_GetDeviceSubunit(device_desc, subunit_desc, "{7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC}") + if !avl + return + VA_IPerChannelDbLevel_GetChannelCount(avl, channel_count) + if channel = + { + vol = 0 + + Loop, %channel_count% + { + VA_IPerChannelDbLevel_GetLevelRange(avl, A_Index-1, min_dB, max_dB, step_dB) + VA_IPerChannelDbLevel_GetLevel(avl, A_Index-1, this_vol) + this_vol := VA_dB2Scalar(this_vol, min_dB, max_dB) + + ; "Speakers Properties" reports the highest channel as the volume. + if (this_vol > vol) + vol := this_vol + } + } + else if channel between 1 and channel_count + { + channel -= 1 + VA_IPerChannelDbLevel_GetLevelRange(avl, channel, min_dB, max_dB, step_dB) + VA_IPerChannelDbLevel_GetLevel(avl, channel, vol) + vol := VA_dB2Scalar(vol, min_dB, max_dB) + } + COM_Release(avl) + return vol +} + +VA_SetVolume(vol, subunit_desc="1", channel="", device_desc="playback") +{ + avl := VA_GetDeviceSubunit(device_desc, subunit_desc, "{7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC}") + if !avl + return + + vol := vol<0 ? 0 : vol>100 ? 100 : vol + + VA_IPerChannelDbLevel_GetChannelCount(avl, channel_count) + + if channel = + { + ; Simple method -- resets balance to "center": + ;VA_IPerChannelDbLevel_SetLevelUniform(avl, vol) + + vol_max = 0 + + Loop, %channel_count% + { + VA_IPerChannelDbLevel_GetLevelRange(avl, A_Index-1, min_dB, max_dB, step_dB) + VA_IPerChannelDbLevel_GetLevel(avl, A_Index-1, this_vol) + this_vol := VA_dB2Scalar(this_vol, min_dB, max_dB) + + channel%A_Index%vol := this_vol + channel%A_Index%min := min_dB + channel%A_Index%max := max_dB + + ; Scale all channels relative to the loudest channel. + ; (This is how Vista's "Speakers Properties" dialog seems to work.) + if (this_vol > vol_max) + vol_max := this_vol + } + + Loop, %channel_count% + { + this_vol := channel%A_Index%vol / vol_max * vol + this_vol := VA_Scalar2dB(this_vol/100, channel%A_Index%min, channel%A_Index%max) + VA_IPerChannelDbLevel_SetLevel(avl, A_Index-1, this_vol) + } + } + else if channel between 1 and %channel_count% + { + channel -= 1 + VA_IPerChannelDbLevel_GetLevelRange(avl, channel, min_dB, max_dB, step_dB) + VA_IPerChannelDbLevel_SetLevel(avl, channel, VA_Scalar2dB(vol/100, min_dB, max_dB)) + } + COM_Release(avl) +} + +VA_GetChannelCount(subunit_desc="1", device_desc="playback") +{ + avl := VA_GetDeviceSubunit(device_desc, subunit_desc, "{7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC}") + if !avl + return + VA_IPerChannelDbLevel_GetChannelCount(avl, channel_count) + COM_Release(avl) + return channel_count +} + +VA_SetMute(mute, subunit_desc="1", device_desc="playback") +{ + amute := VA_GetDeviceSubunit(device_desc, subunit_desc, "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}") + if !amute + return + VA_IAudioMute_SetMute(amute, mute) + COM_Release(amute) +} + +VA_GetMute(subunit_desc="1", device_desc="playback") +{ + amute := VA_GetDeviceSubunit(device_desc, subunit_desc, "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}") + if !amute + return + VA_IAudioMute_GetMute(amute, muted) + COM_Release(amute) + return muted +} + +; +; AUDIO METERING +; + +VA_GetAudioMeter(device_desc="playback") +{ + if ! device := VA_GetDevice(device_desc) + return 0 + VA_IMMDevice_Activate(device, "{C02216F6-8C67-4B5B-9D00-D008E73E0064}", 7, 0, audioMeter) + return audioMeter +} + +VA_GetDevicePeriod(device_desc, ByRef default_period, ByRef minimum_period="") +{ + defaultPeriod := minimumPeriod := 0 + if ! device := VA_GetDevice(device_desc) + return false + VA_IMMDevice_Activate(device, "{1CB9AD4C-DBFA-4c32-B178-C2F568A703B2}", 7, 0, audioClient) + COM_Release(device) + ; IAudioClient::GetDevicePeriod + DllCall(NumGet(NumGet(audioClient+0)+36), "uint",audioClient, "int64*",default_period, "int64*",minimum_period) + ; Convert 100-nanosecond units to milliseconds. + default_period /= 10000 + minimum_period /= 10000 + COM_Release(audioClient) + return true +} + + +/* IID + COM_GUID4String(IID_IAudioEndpointVolume,"{5CDF2C82-841E-4546-9722-0CF74078229A}") + COM_GUID4String(IID_IAudioVolumeLevel,"{7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC}") + COM_GUID4String(IID_IAudioMute,"{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}") + COM_GUID4String(IID_IAudioAutoGainControl,"{85401FD4-6DE4-4b9d-9869-2D6753A82F3C}") +*/ + +VA_GetAudioEndpointVolume(device_desc="playback") +{ + if ! device := VA_GetDevice(device_desc) + return 0 + VA_IMMDevice_Activate(device, "{5CDF2C82-841E-4546-9722-0CF74078229A}", 7, 0, endpointVolume) + COM_Release(device) + return endpointVolume +} + +VA_GetDeviceSubunit(device_desc, subunit_desc, subunit_iid) +{ + device := VA_GetDevice(device_desc) + if !device + return 0 + subunit := VA_FindSubunit(device, subunit_desc, subunit_iid) + COM_Release(device) + return subunit +} + +VA_FindSubunit(device, target_desc, target_iid) +{ + if target_desc is integer + target_index := target_desc + else + RegExMatch(target_desc, "(?<_name>.*?)(?::(?<_index>\d+))?$", target) + ; v2.01: Since target_name is now a regular expression, default to case-insensitive mode if no options are specified. + if !RegExMatch(target_name,"[imsxADJUXPS`n`r`a ]+\)") + target_name := "i)" target_name + ; cbinfo: + ; @0 target_index + ; @4 current_index + VarSetCapacity(cbinfo, 8, 0) + NumPut(target_index ? target_index : 1, cbinfo, 0) + r := VA_EnumSubunits(device, "VA_FindSubunitCallback", target_name, target_iid, &cbinfo) + DllCall("GlobalFree", "uint", callback) + return r +} + +VA_FindSubunitCallback(part, interface, prm) +{ + NumPut(index := 1 + NumGet(prm+4), prm+4) + if NumGet(prm+0) = index + { + COM_AddRef(interface) + return interface + } +} + +VA_EnumSubunits(device, callback, target_name="", target_iid="", callback_param="") +{ + VA_IMMDevice_Activate(device, "{2A07407E-6497-4A18-9787-32F79BD0D98F}", 7, 0, deviceTopology) + VA_IDeviceTopology_GetConnector(deviceTopology, 0, conn) + COM_Release(deviceTopology) + VA_IConnector_GetConnectedTo(conn, conn_to) + VA_IConnector_GetDataFlow(conn, data_flow) + COM_Release(conn) + if !conn_to + return ; blank to indicate error + part := COM_QueryInterface(conn_to, "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}") + COM_Release(conn_to) + r := VA_EnumSubunitsEx(part, data_flow, callback, target_name, target_iid, callback_param) + COM_Release(part) + return r ; value returned by callback, or zero. +} + +VA_EnumSubunitsEx(part, data_flow, callback, target_name="", target_iid="", callback_param="") +{ + r := 0 + + VA_IPart_GetPartType(part, type) + + if type = 1 ; Subunit + { + VA_IPart_GetName(part, name) + + ; v2.01: target_name is now a regular expression. + if RegExMatch(name, target_name) + { + if target_iid = + r := %callback%(part, 0, callback_param) + else + if VA_IPart_Activate(part, 7, target_iid, interface) = 0 + { + r := %callback%(part, interface, callback_param) + ; The callback is responsible for calling COM_AddRef() + ; if it intends to keep the interface pointer. + COM_Release(interface) + } + + if r + return r ; early termination + } + } + + if data_flow = 0 + VA_IPart_EnumPartsIncoming(part, parts) + else + VA_IPart_EnumPartsOutgoing(part, parts) + + VA_IPartsList_GetCount(parts, count) + Loop %count% + { + VA_IPartsList_GetPart(parts, A_Index-1, subpart) + r := VA_EnumSubunitsEx(subpart, data_flow, callback, target_name, target_iid, callback_param) + COM_Release(subpart) + if r + break ; early termination + } + COM_Release(parts) + return r ; continue/finished enumeration +} + +; device_desc = device_id +; | ( friendly_name | 'playback' | 'capture' ) [ ':' index ] +VA_GetDevice(device_desc="playback") +{ + if ! deviceEnumerator := COM_CreateObject("{BCDE0395-E52F-467C-8E3D-C4579291692E}","{A95664D2-9614-4F35-A746-DE8DB63617E6}") + return 0 + + device := 0 + + ; deviceEnumerator->GetDevice(device_id, [out] device) + if DllCall(NumGet(NumGet(deviceEnumerator+0)+20), "uint",deviceEnumerator, "uint",COM_Unicode4Ansi(wstr, device_desc), "uint*",device) = 0 + goto VA_GetDevice_Return + + if device_desc is integer + m2 := device_desc + else + RegExMatch(device_desc, "(.*?)\s*(?::(\d+))?$", m) + + if m1 in playback,p + m1 := "", flow := 0 ; eRender + else if m1 in capture,c + m1 := "", flow := 1 ; eCapture + else if (m1 . m2) = "" ; no name or number specified + m1 := "", flow := 0 ; eRender (default) + else + flow := 2 ; eAll + + if (m1 . m2) = "" ; no name or number (maybe "playback" or "capture") + { ; deviceEnumerator->GetDefaultAudioEndpoint(dataFlow, role, [out] device) + DllCall(NumGet(NumGet(deviceEnumerator+0)+16), "uint",deviceEnumerator, "uint",flow, "uint",0, "uint*",device) + goto VA_GetDevice_Return + } + + ; deviceEnumerator->EnumAudioEndpoints(dataFlow, stateMask, [out] devices) + DllCall(NumGet(NumGet(deviceEnumerator+0)+12), "uint",deviceEnumerator, "uint",flow, "uint",1, "uint*",devices) + + ; devices->GetCount([out] count) + DllCall(NumGet(NumGet(devices+0)+12), "uint",devices, "uint*",count) + + if m1 = + { ; devices->Item(m2-1, [out] device) + DllCall(NumGet(NumGet(devices+0)+16), "uint",devices, "uint",m2-1, "uint*",device) + goto VA_GetDevice_Return + } + + index := 0 + Loop % count + ; devices->Item(A_Index-1, [out] device) + if DllCall(NumGet(NumGet(devices+0)+16), "uint",devices, "uint",A_Index-1, "uint*",device) = 0 + if InStr(VA_GetDeviceName(device), m1) && (m2 = "" || ++index = m2) + goto VA_GetDevice_Return + else + COM_Release(device), device:=0 + +VA_GetDevice_Return: + COM_Release(deviceEnumerator) + if devices + COM_Release(devices) + + return device ; may be 0 +} + +VA_GetDeviceName(device) +{ + static PKEY_Device_FriendlyName + if !VarSetCapacity(PKEY_Device_FriendlyName) + VarSetCapacity(PKEY_Device_FriendlyName, 20) + ,COM_GUID4String(PKEY_Device_FriendlyName, "{A45C254E-DF1C-4EFD-8020-67D146A850E0}") + ,NumPut(14, PKEY_Device_FriendlyName, 16) + VarSetCapacity(prop, 16) + VA_IMMDevice_OpenPropertyStore(device, 0, store) + ; store->GetValue(.., [out] prop) + DllCall(NumGet(NumGet(store+0)+20), "uint",store, "uint",&PKEY_Device_FriendlyName, "uint",&prop) + COM_Release(store) + return COM_Ansi4Unicode(NumGet(prop,8)), COM_CoTaskMemFree(NumGet(prop,8)) +} + + +VA_dB2Scalar(dB, min_dB, max_dB) { + min_s := 10**(min_dB/20), max_s := 10**(max_dB/20) + return ((10**(dB/20))-min_s)/(max_s-min_s)*100 +} + +VA_Scalar2dB(s, min_dB, max_dB) { + min_s := 10**(min_dB/20), max_s := 10**(max_dB/20) + return log((max_s-min_s)*s+min_s)*20 +} + + +; +; INTERFACE WRAPPERS +; Reference: Core Audio APIs in Windows Vista -- Programming Reference +; http://msdn2.microsoft.com/en-us/library/ms679156(VS.85).aspx +; + +; +; IMMDevice +; +VA_IMMDevice_Activate(this, iid, ClsCtx, ActivationParams, ByRef Interface) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "uint", COM_GUID4String(iid,iid), "uint", ClsCtx, "uint", ActivationParams, "uint*", Interface) +} +VA_IMMDevice_OpenPropertyStore(this, Access, ByRef Properties) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint", Access, "uint*", Properties) +} +VA_IMMDevice_GetId(this, ByRef Id) { + hr := DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint*", Id) + Id := (COM_Ansi4Unicode(Id),COM_CoTaskMemFree(Id)) + return hr +} +VA_IMMDevice_GetState(this, ByRef State) { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this, "uint*", State) +} + +; +; IDeviceTopology +; +VA_IDeviceTopology_GetConnectorCount(this, ByRef Count) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "uint*", Count) +} +VA_IDeviceTopology_GetConnector(this, Index, ByRef Connector) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint", Index, "uint*", Connector) +} +VA_IDeviceTopology_GetSubunitCount(this, ByRef Count) { + return DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint*", Count) +} +VA_IDeviceTopology_GetSubunit(this, Index, ByRef Subunit) { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this, "uint", Index, "uint*", Subunit) +} +VA_IDeviceTopology_GetPartById(this, Id, ByRef Part) { + return DllCall(NumGet(NumGet(this+0)+28), "uint", this, "uint", Id, "uint*", Part) +} +VA_IDeviceTopology_GetDeviceId(this, ByRef DeviceId) { + hr := DllCall(NumGet(NumGet(this+0)+32), "uint", this, "uint*", DeviceId) + DeviceId := (COM_Ansi4Unicode(DeviceId),COM_CoTaskMemFree(DeviceId)) + return hr +} +VA_IDeviceTopology_GetSignalPath(this, PartFrom, PartTo, RejectMixedPaths, ByRef Parts) { + return DllCall(NumGet(NumGet(this+0)+36), "uint", this, "uint", PartFrom, "uint", PartTo, "int", RejectMixedPaths, "uint*", Parts) +} + +; +; IConnector +; +VA_IConnector_GetType(this, ByRef Type) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "int*", Type) +} +VA_IConnector_GetDataFlow(this, ByRef Flow) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "int*", Flow) +} +VA_IConnector_ConnectTo(this, ConnectTo) { + return DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint", ConnectTo) +} +VA_IConnector_Disconnect(this) { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this) +} +VA_IConnector_IsConnected(this, ByRef Connected) { + return DllCall(NumGet(NumGet(this+0)+28), "uint", this, "int*", Connected) +} +VA_IConnector_GetConnectedTo(this, ByRef ConTo) { + return DllCall(NumGet(NumGet(this+0)+32), "uint", this, "uint*", ConTo) +} +VA_IConnector_GetConnectorIdConnectedTo(this, ByRef ConnectorId) { + hr := DllCall(NumGet(NumGet(this+0)+36), "uint", this, "uint*", ConnectorId) + ConnectorId := (COM_Ansi4Unicode(ConnectorId),COM_CoTaskMemFree(ConnectorId)) + return hr +} +VA_IConnector_GetDeviceIdConnectedTo(this, ByRef DeviceId) { + hr := DllCall(NumGet(NumGet(this+0)+40), "uint", this, "uint*", DeviceId) + DeviceId := (COM_Ansi4Unicode(DeviceId),COM_CoTaskMemFree(DeviceId)) + return hr +} + +; +; IPart +; +VA_IPart_GetName(this, ByRef Name) { + hr := DllCall(NumGet(NumGet(this+0)+12), "uint", this, "uint*", Name) + Name := (COM_Ansi4Unicode(Name),COM_CoTaskMemFree(Name)) + return hr +} +VA_IPart_GetLocalId(this, ByRef Id) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint*", Id) +} +VA_IPart_GetGlobalId(this, ByRef GlobalId) { + hr := DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint*", GlobalId) + GlobalId := (COM_Ansi4Unicode(GlobalId),COM_CoTaskMemFree(GlobalId)) + return hr +} +VA_IPart_GetPartType(this, ByRef PartType) { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this, "int*", PartType) +} +VA_IPart_GetSubType(this, ByRef SubType) { + VarSetCapacity(SubType,16,0) + hr := DllCall(NumGet(NumGet(this+0)+28), "uint", this, "uint", &SubType) + SubType := COM_String4GUID(&SubType) + return hr +} +VA_IPart_GetControlInterfaceCount(this, ByRef Count) { + return DllCall(NumGet(NumGet(this+0)+32), "uint", this, "uint*", Count) +} +VA_IPart_GetControlInterface(this, Index, ByRef InterfaceDesc) { + return DllCall(NumGet(NumGet(this+0)+36), "uint", this, "uint", Index, "uint*", InterfaceDesc) +} +VA_IPart_EnumPartsIncoming(this, ByRef Parts) { + return DllCall(NumGet(NumGet(this+0)+40), "uint", this, "uint*", Parts) +} +VA_IPart_EnumPartsOutgoing(this, ByRef Parts) { + return DllCall(NumGet(NumGet(this+0)+44), "uint", this, "uint*", Parts) +} +VA_IPart_GetTopologyObject(this, ByRef Topology) { + return DllCall(NumGet(NumGet(this+0)+48), "uint", this, "uint*", Topology) +} +VA_IPart_Activate(this, ClsContext, iid, ByRef Object) { + return DllCall(NumGet(NumGet(this+0)+52), "uint", this, "uint", ClsContext, "uint", COM_GUID4String(iid,iid), "uint*", Object) +} +VA_IPart_RegisterControlChangeCallback(this, iid, Notify) { + return DllCall(NumGet(NumGet(this+0)+56), "uint", this, "uint", COM_GUID4String(iid,iid), "uint", Notify) +} +VA_IPart_UnregisterControlChangeCallback(this, Notify) { + return DllCall(NumGet(NumGet(this+0)+60), "uint", this, "uint", Notify) +} + +; +; IPartsList +; +VA_IPartsList_GetCount(this, ByRef Count) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "uint*", Count) +} +VA_IPartsList_GetPart(this, INdex, ByRef Part) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint", INdex, "uint*", Part) +} + +; +; IAudioEndpointVolume +; +VA_IAudioEndpointVolume_RegisterControlChangeNotify(this, Notify) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "uint", Notify) +} +VA_IAudioEndpointVolume_UnregisterControlChangeNotify(this, Notify) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint", Notify) +} +VA_IAudioEndpointVolume_GetChannelCount(this, ByRef ChannelCount) { + return DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint*", ChannelCount) +} +VA_IAudioEndpointVolume_SetMasterVolumeLevel(this, LevelDB, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this, "float", LevelDB, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_SetMasterVolumeLevelScalar(this, Level, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+28), "uint", this, "float", Level, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_GetMasterVolumeLevel(this, ByRef LevelDB) { + return DllCall(NumGet(NumGet(this+0)+32), "uint", this, "float*", LevelDB) +} +VA_IAudioEndpointVolume_GetMasterVolumeLevelScalar(this, ByRef Level) { + return DllCall(NumGet(NumGet(this+0)+36), "uint", this, "float*", Level) +} +VA_IAudioEndpointVolume_SetChannelVolumeLevel(this, Channel, LevelDB, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+40), "uint", this, "uint", Channel, "float", LevelDB, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_SetChannelVolumeLevelScalar(this, Channel, Level, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+44), "uint", this, "uint", Channel, "float", Level, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_GetChannelVolumeLevel(this, Channel, ByRef LevelDB) { + return DllCall(NumGet(NumGet(this+0)+48), "uint", this, "uint", Channel, "float*", LevelDB) +} +VA_IAudioEndpointVolume_GetChannelVolumeLevelScalar(this, Channel, ByRef Level) { + return DllCall(NumGet(NumGet(this+0)+52), "uint", this, "uint", Channel, "float*", Level) +} +VA_IAudioEndpointVolume_SetMute(this, Mute, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+56), "uint", this, "int", Mute, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_GetMute(this, ByRef Mute) { + return DllCall(NumGet(NumGet(this+0)+60), "uint", this, "int*", Mute) +} +VA_IAudioEndpointVolume_GetVolumeStepInfo(this, ByRef Step, ByRef StepCount) { + return DllCall(NumGet(NumGet(this+0)+64), "uint", this, "uint*", Step, "uint*", StepCount) +} +VA_IAudioEndpointVolume_VolumeStepUp(this, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+68), "uint", this, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_VolumeStepDown(this, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+72), "uint", this, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioEndpointVolume_QueryHardwareSupport(this, ByRef HardwareSupportMask) { + return DllCall(NumGet(NumGet(this+0)+76), "uint", this, "uint*", HardwareSupportMask) +} +VA_IAudioEndpointVolume_GetVolumeRange(this, ByRef MinDB, ByRef MaxDB, ByRef IncrementDB) { + return DllCall(NumGet(NumGet(this+0)+80), "uint", this, "float*", MinDB, "float*", MaxDB, "float*", IncrementDB) +} + +; +; IPerChannelDbLevel +; Applies to IAudioVolumeLevel, IAudioBass, IAudioMidrange and IAudioTreble. +; +VA_IPerChannelDbLevel_GetChannelCount(this, ByRef Channels) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "uint*", Channels) +} +VA_IPerChannelDbLevel_GetLevelRange(this, Channel, ByRef MinLevelDB, ByRef MaxLevelDB, ByRef Stepping) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint", Channel, "float*", MinLevelDB, "float*", MaxLevelDB, "float*", Stepping) +} +VA_IPerChannelDbLevel_GetLevel(this, Channel, ByRef LevelDB) { + return DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint", Channel, "float*", LevelDB) +} +VA_IPerChannelDbLevel_SetLevel(this, Channel, LevelDB, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this, "uint", Channel, "float", LevelDB, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IPerChannelDbLevel_SetLevelUniform(this, LevelDB, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+28), "uint", this, "float", LevelDB, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IPerChannelDbLevel_SetLevelAllChannels(this, LevelsDB, ChannelCount, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+32), "uint", this, "uint", LevelsDB, "uint", ChannelCount, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} + +; +; IAudioMute +; +VA_IAudioMute_SetMute(this, Muted, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "int", Muted, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} +VA_IAudioMute_GetMute(this, ByRef Muted) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "int*", Muted) +} + +; +; IAudioAutoGainControl +; +VA_IAudioAutoGainControl_GetEnabled(this, ByRef Enabled) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "int*", Enabled) +} +VA_IAudioAutoGainControl_SetEnabled(this, Enable, GuidEventContext="") { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "int", Enable, "uint", GuidEventContext ? COM_GUID4String(GuidEventContext,GuidEventContext) : 0) +} + +; +; IAudioMeterInformation +; +VA_IAudioMeterInformation_GetPeakValue(this, ByRef Peak) { + return DllCall(NumGet(NumGet(this+0)+12), "uint", this, "float*", Peak) +} +VA_IAudioMeterInformation_GetMeteringChannelCount(this, ByRef ChannelCount) { + return DllCall(NumGet(NumGet(this+0)+16), "uint", this, "uint*", ChannelCount) +} +VA_IAudioMeterInformation_GetChannelsPeakValues(this, ChannelCount, PeakValues) { + return DllCall(NumGet(NumGet(this+0)+20), "uint", this, "uint", ChannelCount, "uint", PeakValues) +} +VA_IAudioMeterInformation_QueryHardwareSupport(this, ByRef HardwareSupportMask) { + return DllCall(NumGet(NumGet(this+0)+24), "uint", this, "uint*", HardwareSupportMask) +} diff --git a/VolumeOSD.ahk b/VolumeOSD.ahk new file mode 100644 index 0000000..ab83276 --- /dev/null +++ b/VolumeOSD.ahk @@ -0,0 +1,107 @@ +; Volume On-Screen-Display (OSD) -- by Rajat +; http://www.autohotkey.com +; This script assigns hotkeys of your choice to raise and lower the +; master and/or wave volume. Both volumes are displayed as different +; color bar graphs. + +;_________________________________________________ +;_______User Settings_____________________________ + +; Make customisation only in this area or hotkey area only!! + +; The percentage by which to raise or lower the volume each time: +vol_Step = 4 + +; How long to display the volume level bar graphs: +vol_DisplayTime = 2000 + +; Master Volume Bar color (see the help file to use more +; precise shades): +vol_CBM = Lime + +; Background color; for transparent, set to 111111 +vol_CW = 111111 + +; Bar's screen position. Use -1 to center the bar in that dimension: +vol_PosX = -1 +vol_PosY = 600 +vol_Width = 400 ; width of bar +vol_Thick = 20 ; thickness of bar + +; If your keyboard has multimedia buttons for Volume, you can +; try changing the below hotkeys to use them by specifying +; Volume_Up, ^Volume_Up, Volume_Down, and ^Volume_Down: +;HotKey, Volume_Up, vol_MasterUp +;HotKey, Volume_Down, vol_MasterDown + +HotKey, #Up, vol_MasterUp ; Win+UpArrow +HotKey, #Down, vol_MasterDown +HotKey, ^!Up, vol_MasterUp ; Ctrl+Alt+UpArrow +HotKey, ^!Down, vol_MasterDown + + +;___________________________________________ +;_____Auto Execute Section__________________ + +; DON'T CHANGE ANYTHING HERE (unless you know what you're doing). + +COM_Init() + +vol_BarOptionsMaster = 1 ZH%vol_Thick% ZX0 ZY0 W%vol_Width% CB%vol_CBM% CW%vol_CW% +;vol_BarOptionsMaster = 1 ZH%vol_Thick% ZX0 ZY0 W%vol_Width% + +; If the X position has been specified, add it to the options. +; Otherwise, omit it to center the bar horizontally: +if vol_PosX >= 0 +{ + vol_BarOptionsMaster = %vol_BarOptionsMaster% X%vol_PosX% +} + +; If the Y position has been specified, add it to the options. +; Otherwise, omit it to have it calculated later: +if vol_PosY >= 0 +{ + vol_BarOptionsMaster = %vol_BarOptionsMaster% Y%vol_PosY% +} + +#SingleInstance +SetBatchLines, 10ms +Return + + +;___________________________________________ + +vol_MasterUp: +vol_tmp := VA_GetMasterVolume() +vol_Master := (vol_tmp + vol_Step) +VA_SetMasterVolume(vol_Master) +Gosub, vol_ShowBars +return + +vol_MasterDown: +vol_tmp := VA_GetMasterVolume() +vol_Master := (vol_tmp - vol_Step) +VA_SetMasterVolume(vol_Master) +Gosub, vol_ShowBars +return + +vol_ShowBars: +; To prevent the "flashing" effect, only create the bar window if it +; doesn't already exist: +IfWinNotExist, vol_Progress +{ + ; Calculate position here in case screen resolution changes while + ; the script is running: + Progress, %vol_BarOptionsMaster%, , , vol_Progress + ;WinSet, TransColor, 111111, vol_Progress +} +; Get the volume in case the user or an external program changed them: +vol_Master := VA_GetMasterVolume() +Progress, 1:%vol_Master% +SetTimer, vol_BarOff, %vol_DisplayTime% +return + +vol_BarOff: +SetTimer, vol_BarOff, off +Progress, 1:Off +return \ No newline at end of file diff --git a/Winamp.ahk b/Winamp.ahk new file mode 100644 index 0000000..c83b282 --- /dev/null +++ b/Winamp.ahk @@ -0,0 +1,85 @@ +;############## +;### WINAMP ### +; http://www.autohotkey.com/docs/misc/Winamp.htm +; http://www.autohotkey.com/forum/topic155.html +; http://www.autohotkey.com/forum/topic126.html +; Ctrl+Alt+Z/X/C/V/B/Up/Down/Left/Right = Control Winamp +^!z:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, z ; Previous Track +PostMessage, 0x111, 40044, , ,ahk_class Winamp v1.x ; Previous Track +return + +^!x:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, x ; Play/Restart/UnPause +PostMessage, 0x111, 40045, , ,ahk_class Winamp v1.x ; Play/Restart/UnPause +return + +^!c:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, c ; Pause/UnPause +PostMessage, 0x111, 40046, , ,ahk_class Winamp v1.x ; Pause/UnPause +return + +^!v:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, v ; Stop +PostMessage, 0x111, 40047, , ,ahk_class Winamp v1.x ; Stop +return + +^!b:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, b ; Next Track +PostMessage, 0x111, 40048, , ,ahk_class Winamp v1.x ; Next Track +return + +;^!Up:: +;IfWinNotExist ahk_class Winamp v1.x +; return +;; Otherwise, the above has set the "last found" window for use below. +;;ControlSend, ahk_parent, b ; Next Track +;PostMessage, 0x111, 40058 , , ,ahk_class Winamp v1.x ; Raise Volume +;PostMessage, 0x111, 40058 , , ,ahk_class Winamp v1.x ; Raise Volume +;PostMessage, 0x111, 40058 , , ,ahk_class Winamp v1.x ; Raise Volume +;PostMessage, 0x111, 40058 , , ,ahk_class Winamp v1.x ; Raise Volume +;PostMessage, 0x111, 40058 , , ,ahk_class Winamp v1.x ; Raise Volume +;return + +;^!Down:: +;IfWinNotExist ahk_class Winamp v1.x +; return +;; Otherwise, the above has set the "last found" window for use below. +;;ControlSend, ahk_parent, b ; Next Track +;PostMessage, 0x111, 40059 , , ,ahk_class Winamp v1.x ; Lower Volume +;PostMessage, 0x111, 40059 , , ,ahk_class Winamp v1.x ; Lower Volume +;PostMessage, 0x111, 40059 , , ,ahk_class Winamp v1.x ; Lower Volume +;PostMessage, 0x111, 40059 , , ,ahk_class Winamp v1.x ; Lower Volume +;PostMessage, 0x111, 40059 , , ,ahk_class Winamp v1.x ; Lower Volume +;return + +^!Left:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, z ; Previous Track +PostMessage, 0x111, 40044, , ,ahk_class Winamp v1.x ; Previous Track +return + +^!Right:: +IfWinNotExist ahk_class Winamp v1.x + return +; Otherwise, the above has set the "last found" window for use below. +;ControlSend, ahk_parent, b ; Next Track +PostMessage, 0x111, 40048, , ,ahk_class Winamp v1.x ; Next Track +return -- 2.45.2