Jump to content
nacerbaaziz

how to change any program volume by it handle

Recommended Posts

good morning autoit team

please i need your help

am trying to make an program that work with hotkeys

it function is to change the volume to the current application

e.g when i select the vlc window by using this hotkey i will be able to change the vlc volume with out changing the system volume.

 am able to get the process handle and the process name of the window

but when am trying to get or set the volume i does not succeded

i tried to search in this forums but no result.

can you please guide me to do that.

am waiting for your answers

thanks in advanced

Share this post


Link to post
Share on other sites

..had a hard time understanding the title. Do change it to "how to change any program's sound volume by it handle".
and sorry but I have no clue of how to do that. ( But pressing up key or down key while in VLC it'll go sound volume up or down. )

Share this post


Link to post
Share on other sites
Posted (edited)
Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Had this code saved from somewhere in the forum, made some tweaks to allow volume to be changed with the keyboard arrows.

The only thing you have to give is a processname. Adapt to your needs.

#include-once
;https://www.autoitscript.com/forum/topic/174460-is-there-a-way-to-detect-any-sound-file-played/
;Special Thanks to Danyfirex 02/08/2015
#include <WinAPIProc.au3>
#include <Array.au3>
#include <Misc.au3>


Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $sTagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"

Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $sTagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"

Global Const $sIID_IAudioSessionManager2 = "{77aa99a0-1bd6-484f-8bc7-2c654c9a9b6f}"
Global Const $sTagIAudioSessionManager = "GetAudioSessionControl hresult(ptr;dword;ptr*);" & _
        "GetSimpleAudioVolume hresult(ptr;dword;ptr*);"
Global Const $sTagIAudioSessionManager2 = $sTagIAudioSessionManager & "GetSessionEnumerator hresult(ptr*);" & _
        "RegisterSessionNotification hresult(ptr);" & _
        "UnregisterSessionNotification hresult(ptr);" & _
        "RegisterDuckNotification hresult(wstr;ptr);" & _
        "UnregisterDuckNotification hresult(ptr)"

Global Const $sIID_IAudioSessionEnumerator = "{e2f5bb11-0570-40ca-acdd-3aa01277dee8}"
Global Const $sTagIAudioSessionEnumerator = "GetCount hresult(int*);GetSession hresult(int;ptr*)"

Global Const $sIID_IAudioSessionControl = "{f4b1a599-7266-4319-a8ca-e70acb11e8cd}"
Global Const $sTagIAudioSessionControl = "GetState hresult(int*);GetDisplayName hresult(ptr);" & _
        "SetDisplayName hresult(wstr);GetIconPath hresult(ptr);" & _
        "SetIconPath hresult(wstr;ptr);GetGroupingParam hresult(ptr*);" & _
        "SetGroupingParam hresult(ptr;ptr);RegisterAudioSessionNotification hresult(ptr);" & _
        "UnregisterAudioSessionNotification hresult(ptr);"

Global Const $sIID_IAudioSessionControl2 = "{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}"
Global Const $sTagIAudioSessionControl2 = $sTagIAudioSessionControl & "GetSessionIdentifier hresult(ptr)" & _
        "GetSessionInstanceIdentifier hresult(ptr);" & _
        "GetProcessId hresult(dword*);IsSystemSoundsSession hresult();" & _
        "SetDuckingPreferences hresult(bool);"

; http://answers.awesomium.com/questions/3398/controlling-the-sound-using-pinvoke-the-volume-mix.html
Global Const $sIID_ISimpleAudioVolume = "{87CE5498-68D6-44E5-9215-6DA47EF883D8}"
Global Const $sTagISimpleAudioVolume = _
        "SetMasterVolume hresult(float;ptr);" & _
        "GetMasterVolume hresult(float*);" & _
        "SetMute hresult(int;ptr);" & _
        "GetMute hresult(int*)"
Global $__oIAudioSessionManager2

Local $PList = ProcessList()
_ArrayDisplay($PList)
$SoundAPP = InputBox('Process name', 'What is the process name?', 'firefox.exe')
Local $CurrentVolume = Audio_GetMasterVolume(_GetProcessID_by_name($SoundAPP)) * 100
Local $Vol = $CurrentVolume
MsgBox(64 + 262144, $Vol, $SoundAPP)
Local $SMV
While 1
If _IsPressed(26) Then
    ConsoleWrite('UP! ' &$Vol&@CRLF)
        $Vol = $Vol+1
        Audio_SetMasterVolume(_GetProcessID_by_name($SoundAPP), $Vol/ 100)
        ConsoleWrite('$SMV:'& $SMV&@CRLF)
        Sleep(10)
EndIf
If _IsPressed(28) Then
    ConsoleWrite('DOWN! ' &$Vol&@CRLF)
        $Vol = $Vol-1
        $SMV=Audio_SetMasterVolume(_GetProcessID_by_name($SoundAPP), $Vol/ 100)
        ConsoleWrite('$SMV:'& $SMV&@CRLF)
        Sleep(10)
EndIf
$CurrentVolume = Round(Audio_GetMasterVolume(_GetProcessID_by_name($SoundAPP)) * 100, 0)
ConsoleWrite('CV:'&$CurrentVolume &@CRLF)
Sleep(100)
WEnd

Func _GetProcessID_by_name($process_name)
    Local $Process_list = ProcessList()
    Local $ProcessID_Func = 0
    For $i = 1 To UBound($Process_list) - 1
        If $Process_list[$i][0] = $process_name Then
            $ProcessID_Func = $Process_list[$i][1]
            ExitLoop
        EndIf
    Next
Return  $ProcessID_Func
EndFunc   ;==>_SoundAPP_setVolume

Func Audio_SetMasterVolume($pid, $value)
    If Not IsObj($__oIAudioSessionManager2) Then
        $__oIAudioSessionManager2 = Audio_GetIAudioSessionManager2()
    EndIf
    If Not IsObj($__oIAudioSessionManager2) Then Return

    Local $pIAudioSessionEnumerator, $oIAudioSessionEnumerator
    If $__oIAudioSessionManager2.GetSessionEnumerator($pIAudioSessionEnumerator) < 0 Then Return
    $oIAudioSessionEnumerator = ObjCreateInterface($pIAudioSessionEnumerator, $sIID_IAudioSessionEnumerator, $sTagIAudioSessionEnumerator)
    If Not IsObj($oIAudioSessionEnumerator) Then Return SetError(1)

    Local $i, $nSessions, $pIAudioSessionControl2, $oIAudioSessionControl2
    Local $ProcessID, $oISimpleAudioVolume
    Local $bMute = 0, $error = 1
    If $oIAudioSessionEnumerator.GetCount($nSessions) >= 0 Then
        For $i = 0 To $nSessions - 1
            If $oIAudioSessionEnumerator.GetSession($i, $pIAudioSessionControl2) >= 0 Then
                $oIAudioSessionControl2 = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioSessionControl2, $sTagIAudioSessionControl2)
                If @error Then ContinueLoop
                $oIAudioSessionControl2.GetProcessId($ProcessID)
                If $ProcessID = $pid Then
                    $oISimpleAudioVolume = ObjCreateInterface($pIAudioSessionControl2, $sIID_ISimpleAudioVolume, $sTagISimpleAudioVolume)
                    If @error Then ContinueLoop
                    $oIAudioSessionControl2.AddRef() ;stabilize
                    If $oISimpleAudioVolume.SetMasterVolume($value, 0) >= 0 Then
                        $error = 0
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        Next
    EndIf
    $oISimpleAudioVolume = 0
    $oIAudioSessionControl2 = 0
    $oIAudioSessionEnumerator = 0
    ;MsgBox(0, $error, "App muted: " & $bMute)
    Return SetError($error, 0, $bMute)
EndFunc   ;==>Audio_SetMasterVolume

Func Audio_GetMasterVolume($pid)
    If Not IsObj($__oIAudioSessionManager2) Then
        $__oIAudioSessionManager2 = Audio_GetIAudioSessionManager2()
    EndIf
    If Not IsObj($__oIAudioSessionManager2) Then Return

    Local $pIAudioSessionEnumerator, $oIAudioSessionEnumerator
    If $__oIAudioSessionManager2.GetSessionEnumerator($pIAudioSessionEnumerator) < 0 Then Return
    $oIAudioSessionEnumerator = ObjCreateInterface($pIAudioSessionEnumerator, $sIID_IAudioSessionEnumerator, $sTagIAudioSessionEnumerator)
    If Not IsObj($oIAudioSessionEnumerator) Then Return SetError(1)

    Local $i, $nSessions, $pIAudioSessionControl2, $oIAudioSessionControl2
    Local $ProcessID, $oISimpleAudioVolume
    Local $bMute = 0, $error = 1
    If $oIAudioSessionEnumerator.GetCount($nSessions) >= 0 Then
        For $i = 0 To $nSessions - 1
            If $oIAudioSessionEnumerator.GetSession($i, $pIAudioSessionControl2) >= 0 Then
                $oIAudioSessionControl2 = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioSessionControl2, $sTagIAudioSessionControl2)
                If @error Then ContinueLoop
                $oIAudioSessionControl2.GetProcessId($ProcessID)
                If $ProcessID = $pid Then
                    $oISimpleAudioVolume = ObjCreateInterface($pIAudioSessionControl2, $sIID_ISimpleAudioVolume, $sTagISimpleAudioVolume)
                    If @error Then ContinueLoop
                    $oIAudioSessionControl2.AddRef() ;stabilize
                    If $oISimpleAudioVolume.GetMasterVolume($bMute) >= 0 Then
                        $error = 0
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        Next
    EndIf
    $oISimpleAudioVolume = 0
    $oIAudioSessionControl2 = 0
    $oIAudioSessionEnumerator = 0
    ;MsgBox(0, $error, "App muted: " & $bMute)
    Return SetError($error, 0, $bMute)
EndFunc   ;==>Audio_GetMasterVolume

Func Audio_GetIAudioSessionManager2()
    Local $oIAudioSessionManager2 = 0
    Local Const $eMultimedia = 1, $CLSCTX_INPROC_SERVER = 0x01
    Local $pIMMDevice, $oMMDevice, $pIAudioSessionManager2
    Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $sTagIMMDeviceEnumerator)
    If IsObj($oMMDeviceEnumerator) Then
        If $oMMDeviceEnumerator.GetDefaultAudioEndpoint(0, $eMultimedia, $pIMMDevice) >= 0 Then
            $oMMDevice = ObjCreateInterface($pIMMDevice, $sIID_IMMDevice, $sTagIMMDevice)
            If IsObj($oMMDevice) Then
                If $oMMDevice.Activate(__uuidof($sIID_IAudioSessionManager2), $CLSCTX_INPROC_SERVER, 0, $pIAudioSessionManager2) >= 0 Then
                    $oIAudioSessionManager2 = ObjCreateInterface($pIAudioSessionManager2, $sIID_IAudioSessionManager2, $sTagIAudioSessionManager2)
                EndIf
                $oMMDevice = 0
            EndIf
        EndIf
        $oMMDeviceEnumerator = 0
    EndIf

    If IsObj($oIAudioSessionManager2) Then
        Return $oIAudioSessionManager2
    EndIf
EndFunc   ;==>Audio_GetIAudioSessionManager2

Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Func CLSIDFromString($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    Return $tGUID
EndFunc   ;==>CLSIDFromString

 


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

in the inputbox you have to put one processname that is currently running, which one did you put in, if any? The default is firefox.exe, do you have firefox running?

What is the process name of the application you want to change the volume of?


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      hello autoit team
      please i've a question for you.
      am creating a audio player
      and in this audio player i want to show the current trac info
      such as the total time and the position ... etc
      i know i can show it as label
      but the screen reader for the blind read the text every change
      because it have a screen scan
      what i want is to show this informations but such image or icon
      i mean i need to create
      GUICtrlCreatepic or GUICtrlCreateicon ....
      or some thing as that
      and show this informations as image on it
      i think that i can do that with the 
      _GDIPlus functions
      but i couldn't find the currect way to do it
      i tried the _GDIPlus_GraphicsDrawString
      but i couldn't know how it work
      what i need is a small example that create a GUI
      and add a multy line text to it as graphic or image.
      so i need a simple way because it will changed every sec
      i hope any one can help me to do that
      global $GUI = GUICreate("text", 400, 400) global $label = GUICtrlCreateLabel(GetText(), 10, 10, 380, 380) GUISetState() do sleep(100) until GUIGetMSG() = -3 exit func GetText() return StringFormat("file name is test.mp3 \r\n total time is 00:30:00 \r\n position is 00:05:50") endFunc  
    • By BlueSkyMemory
      Hello guys! I'm a rookie in AutoIt lol.
      I've tried to looking up in MSDN and the UDFs, but it can only get the GUID of a usual partition and with the GUID to control it. Now I have no ways😥.
      Thanks a lot for your help!
    • By PeterVerbeek
      Hi Guys,
      I've noticed that the SoundGetWaveVolume UDF in an older topic isn't working on Windows Vista, 7, 8, 8.1 and 10. It's probably a Windows XP UDF. The UDF below does work. It successfully returns the volume set by SoundSetWaveVolume. It might need checking by the AutoIt community for some synthax finetuning.
      ; #FUNCTION# ==================================================================================================================== ; Name...........: _SoundGetWaveVolume ; Description....: Returns app volume of script, Windows Vista, 7, 8, 10 only ; Syntax.........: _SoundGetWaveVolume([$iValueOnError = -1]) ; Parameters.....: $iValueOnError - Value to return when an error occurs ; Return values..: App volume of script or $iValueOnError at an error ; Error values...: @error = 1 - Unable to create Struct ; @error = 2 - Dll file not found ; @error = 3 - Wrong call so not on Windows Vista, 7, 8 or 10 ; @error = 4 - Internal error, array not returned ; @error = 5 - Volume wasn't received ; @error = 6 - Volume couldn't read ; Author.........: Peter Verbeek ; Modified.......: ; =============================================================================================================================== Func _SoundGetWaveVolume($iValueOnError = -1) Local $LPDWORD,$aMMRESULT,$iVolume $LPDWORD = DllStructCreate("dword") If @error <> 0 Then SetError(1) ; 1 = unable to create Struct Return $iValueOnError EndIf ; get app volume of this script $aMMRESULT = DllCall("winmm.dll","uint","waveOutGetVolume","ptr",0,"long_ptr",DllStructGetPtr($LPDWORD)) Switch @error Case 1 SetError(2) ; 2 = dll file not found Return $iValueOnError Case 2,3,4,5 SetError(3) ; 3 = wrong call so not on Windows Vista, 7, 8 or 10 Return $iValueOnError EndSwitch If not IsArray($aMMRESULT) Then SetError(4) ; 4 = internal error, array not returned Return $iValueOnError EndIf If $aMMRESULT[0] <> 0 Then SetError(5) ; 5 = volume wasn't received Return $iValueOnError EndIf $iVolume = DllStructGetData($LPDWORD,1) If @error <> 0 Then SetError(6) ; 6 = volume couldn't read Return $iValueOnError EndIf Return Round(100*$iVolume/4294967295) ; return in range 0 to 100 as SoundSetWaveVolume() EndFunc  
    • By Skeletor
      Hey All,
      Yes, this is an odd request. 
      But is there a way to bulk up the size of the compiled program? 
      I know many want to reduce it's size, but I want to increase it.
      What methods do you suggest?
    • By PuneetTewani
      #include <IE.au3>
      #include <Tesseract.au3>
      #include <MsgBoxConstants.au3>
      #include <Math.au3>
      #include <FileConstants.au3>
      #include <StringConstants.au3>
      #include <File.au3>
      #include <ScreenCapture.au3>
      #include <sound.au3>
      #Include <WinAPI.au3>
      #include <Date.au3>
       
      $OCR_Result = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)
      $OCR_Result1 = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)
      $OCR_Result2 = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)
      $OCR_Result3 = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)

      $sound = _SoundStatus("C:\ExpertAdvisorBuyAlert.wav")
      while _nowtime < 3.30 pm
          If $sound = True Then
             if $OCR_Result1 > $OCR_Result2
             
          EndIf
      EndIf
      Wend
      Trying to ocr some values on chart in real time(once per minute) and buy/sell securities on basis of alert generated in my software.
      I am struck onto few steps.
      1. On Tesseract Screen Capture indentation parameters. How can we determine the exact parameters if I just want numeric values only.
      2. The Tesseract Screen Capture generates and error Obj1 on line 185 which needs to be resolved.
      3. Sometimes lines get overlapped with values. What to do in that case.
      3. Detecting the sound as and when it approaches and then comparing the ocr values to decide on either buy or sell.
      The values that needs to be fetched are encircled.

×
×
  • Create New...