Jump to content

Is there a better way to do this?


Recommended Posts

I made a script to control the master volume. It works, but I bet it could be improved.

Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)

mastersound(1, 0 ) ;for testing        

func mastersound($level, $mute) ; $level = 1 - 5, $mute - 0 mute off, 1 muted on
    run("sndvol32.exe /t", "", @SW_HIDE) ;window will not hide, need to figure out a workaround
    WinWaitActive("Volume Control", "Volume")
    $clrchk = PixelGetColor(12, 121)
; controls sound level    
    if $level = 0 then sleep(1)
    if $level = 1 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 1}")        
    EndIf
        if $level = 2 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 2}")        
    EndIf
        if $level = 3 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 3}")        
    EndIf
        if $level = 4 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 1}")        
    EndIf    
        if $level = 5 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 8}")        
    EndIf        
; turns on or off mute -     
    if $mute = 0 then 
        if $clrchk = 0x000000 then 
            ControlClick("Volume Control", "Volume", 1000, "left", 1)
        endif
    EndIf    
    if $mute = 1 then 
        if $clrchk = 0xFFFFFF then 
            ControlClick("Volume Control", "Volume", 1000, "left", 1)
        endif
    EndIf        
ProcessClose("sndvol32.exe")   ;close control window
EndFunc
Link to comment
Share on other sites

I made a script to control the master volume. It works, but I bet it could be improved.

Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)

mastersound(1, 0 ) ;for testing        

func mastersound($level, $mute) ; $level = 1 - 5, $mute - 0 mute off, 1 muted on
    run("sndvol32.exe /t", "", @SW_HIDE) ;window will not hide, need to figure out a workaround
    WinWaitActive("Volume Control", "Volume")
    $clrchk = PixelGetColor(12, 121)
; controls sound level    
    if $level = 0 then sleep(1)
    if $level = 1 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 1}")        
    EndIf
        if $level = 2 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 2}")        
    EndIf
        if $level = 3 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 3}")        
    EndIf
        if $level = 4 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 8}")
        ControlSend("Volume Control", "Volume", 1001, "{PGDN 1}")        
    EndIf    
        if $level = 5 then 
        ControlSend("Volume Control", "Volume", 1001, "{PGUP 8}")        
    EndIf        
; turns on or off mute -     
    if $mute = 0 then 
        if $clrchk = 0x000000 then 
            ControlClick("Volume Control", "Volume", 1000, "left", 1)
        endif
    EndIf    
    if $mute = 1 then 
        if $clrchk = 0xFFFFFF then 
            ControlClick("Volume Control", "Volume", 1000, "left", 1)
        endif
    EndIf        
ProcessClose("sndvol32.exe")   ;close control window
EndFuncoÝ÷ Ûú®¢×z+·Æ®¶­s`¦Ö7FW'6÷VæB¶f÷"FW7Fær ¦gVæ2Ö7FW'6÷VæBb33c¶ÆWfVÂÂb33c¶×WFRÒgV÷C³gV÷C²²b33c¶ÆWfVÂÒÒRÂb33c¶×WFS¢Òæ÷B×WFVBFVfVÇBÂÒ×WFV@¢'VâgV÷C·6æGföÃ3"æWR÷BgV÷C²ÂgV÷C²gV÷C²Â5uôDR·væF÷rvÆÂæ÷BFRÂæVVBFòfwW&R÷WBv÷&¶&÷Væ@¢våvD7FfRgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C² ¢²6öçG&öÇ26÷VæBÆWfV¢7vF6b33c¶ÆWfVÀ¢66R¢6ÆVW¢66R¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µtDâÒgV÷C²¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µuUÒgV÷C²¢66R"¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µtDâÒgV÷C²¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µuU'ÒgV÷C²¢66R2¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µtDâÒgV÷C²¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µuU7ÒgV÷C²¢66RB¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µuUÒgV÷C²¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µtDâÒgV÷C²¢66RR¢6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·µuUÒgV÷C²¢VæE7vF6 ¢²GW&ç2öâ÷"öfb×WFRÒ¢bb33c¶×WFRÒFVâ¢6öçG&öÄ6öÖÖæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷CµVä6V6²gV÷C²¢VÇ6P¢6öçG&öÄ6öÖÖæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C´6V6²gV÷C²¢VæD` ¢&ö6W746Æ÷6RgV÷C·6æGföÃ3"æWRgV÷C²¶6Æ÷6R6öçG&öÂvæF÷p¤VæDgVæ

I'll be the $clrchk stuff could be done more directly with ControlCommand(), since you have the control ID of that check box.

:D

P.S. The true hotness would be to just set the volume and mute directly via the COM Object, without the GUI at all. Alas, my AutoIT-fu is not that strong yet.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

; controls sound level   
    Switch $level
        Case 0
            sleep(1)
        Case 1
            ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}{PGUP 1}")
        Case 2
            ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}{PGUP 2}")  
        Case 3
            ControlSend("Volume Control", "Volume", 1001, "{PGDN 8}{PGUP 3}") 
        Case 4
            ControlSend("Volume Control", "Volume", 1001, "{PGUP 8}{PGDN 1}")
        Case 5
            ControlSend("Volume Control", "Volume", 1001, "{PGUP 8}")       
    EndSwitch

    ; turns on or off mute -     
    If $mute Then
        ControlCommand("Volume Control", "Volume", 1000, "Check")
    Else
        ControlCommand("Volume Control", "Volume", 1000, "UnCheck")
    EndIf

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Or you could use Wizmo from GRC in a script and not only control the volume, but the monitor and more...

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

Can anyone figure out a way to do it without the volume control GUI? No matter how I tried, it won't run without the GUI being visible. As soon as the GUI is not visible, it closes. I also tried command line, but to my dismay, the only things I found using google won't run it hidden. Maybe some registry settings???? I didn't have much luch there even when I asked this last time. Anyone care to take a crack at it?

@jefhal:Wizmo???? I'm on 14.4 dialup right now, so my searching ability is very slow.

Link to comment
Share on other sites

Can anyone figure out a way to do it without the volume control GUI?...

run("sndvol32.exe", "", @SW_HIDE)oÝ÷ Û­­¶¿µ8Z¶ËZ®Û-橦uéߢ¹v«z¥j¼"Ú0¶­Êjxbu殶­sbb33cµBÒ'VâgV÷C·6æGföÃ3"æWRgV÷C²ÂgV÷C²gV÷C²Â5uôDR¥våvD7FfRgV÷C²gV÷C²¤6öçG&öÅ6VæBgV÷CµföÇVÖR6öçG&öÂgV÷C²ÂgV÷CµföÇVÖRgV÷C²ÂÂgV÷C·´TäG×µuUÒgV÷C²¥&ö6W746Æ÷6Rb33cµB
Edit: NVM, it work only once... I might have had more that one instance of the app up. Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Opt("WinWaitDelay", 0)
$PID = Run("sndvol32.exe", "")
WinWaitActive("Volume Control")
WinSetTrans("Volume Control", "Volume", 0)
ControlFocus("Volume Control", "Volume", 1001)
ControlSend("Volume Control", "Volume", 1001, "{END}{PGUP 1}")
Sleep(5000)
ControlSend("Volume Control", "Volume", 1001, "{HOME}")
ProcessClose($PID)
only if WinSetTrans works with your OS...

Edit: Warning the "{HOME}" line of code = full volume

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Moderators

Would it not be possible to do this with Send("{VOLUME_UP}" and Send("{VOLUME_DOWN}")?

That's a great point, (Only on 2000/XP though... Not that I think that would matter for the most part for vollyman).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I've been looking for discussion of doing volume control WITHOUT scripting the GUI.

Found some VBS code at Microsoft Support for a project called "Volume.exe", the technique for calling the winmm.dll APIs might be translated to AutoIT.

Also, a C# example that uses winmm.dll, by a user called SFiorito at www.mp3car.com. The code was run through a C# to VBS translator (and tweaked by SFiorito) which lead to VBS code Part One, and Part Two.

Seems the VBS functions should be translatable to AutoIT... (hint, hint) :D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Would it not be possible to do this with Send("{VOLUME_UP}" and Send("{VOLUME_DOWN}")?

Yes and no... Those two do not increment the volume in the same amount that {PGUP} and {PGDN} do.

How many {VOLUME_UP}s in a {PGUP}? :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • 2 months later...

use

VolumeLine 1.0 © 2002, by Slava Glory (Omsk, Russia)

----------------------------------------------------------------------------

June 24, 2002

----------------------------------------------------------------------------

VolumeLine is a command line utility for adjusting volume level through

command line parameters.Supports all available volume, recording and other

mixer controls (master volume, wave, midi, line-in, etc).

How to use:

To get all audio mixers, groups and controls information use:

VolumeLine.exe GET:ALL

To get info about specified audio mixer, group or control use:

VolumeLine.exe GET:<MixerId>[:<GroupId>[:<ControlId>]]

To set volume level for specified audio control use:

VolumeLine.exe SET:<MixerId>:<GroupId>:<ControlId> VOLUME:<0-100>

To set mute for specified audio control use:

VolumeLine.exe SET:<MixerId>:<GroupId>:<ControlId> MUTE:<ON|OFF>

To select specified audio control use:

VolumeLine.exe SET:<MixerId>:<GroupId>:<ControlId> SELECT

Contacts:

E-Mail: slava_glory@mail.ru

Web: http://glorysoft.omsk.ru

VolumeLine IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED

OR IMPLIED. USE AT YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA

LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR

MISUSING THIS SOFTWARE.

Greetings from Schindi! :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...