Jump to content

Control Vista+ Master Volume


Recommended Posts

  • Replies 73
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

UPDATE: With the addition of the ObjCreateInterface function and enhanced COM functionality by trancexxx, these interfaces are now accessible directly in AutoIt. I've rewritten the plugin as a native

Yes that's true of course (I wrote this plugin and UDF after all ), but it is worth noting that those two volume controls on XP *can* be discreet, it may depend on the sound drivers installed. So cha

Just curious, but is this something that can be achieved through the COM interface?

IAudioEndpointVolume Interface (MSDN)

Link to post
Share on other sites

@Ascend4nt

Yes, that's the interface that my plugin uses. It can obviously be used to control all types of volume on Vista/7, but my plugin just focuses on the system Master Volume. I'm not an expert with this interface, so it would take a lot of research to build a full volume control. Not something I'm really interested in doing.

Link to post
Share on other sites

wraithdu, oh okay.. I didn't know. I just thought that using COM objects was part of the AutoIT library and that it would be possible to do it through AutoIT without having to install VC files and DLLs.

But I'm not complaining - I haven't even touched the COM interface myself (looks scary!). Anyway, kudos on nailing down how to do something thats kind of elusive for many.

Link to post
Share on other sites

wraithdu, oh okay.. I didn't know. I just thought that using COM objects was part of the AutoIT library and that it would be possible to do it through AutoIT without having to install VC files and DLLs.

But I'm not complaining - I haven't even touched the COM interface myself (looks scary!). Anyway, kudos on nailing down how to do something thats kind of elusive for many.

There is COM and there is COM. The COM objects that you can use natively in autoit must support the IDispatch interface. The ones wraithdu is using here, the ones DirectX & DirectShow are using do not inherit (they only inherit from IUnknown) from this making it impossible for an application to determine which members & methods it supports during runtime without having the C++ headers from microsoft available (even then it's rather complex).

And yes, I personally think the sound objects on Vista is too damn hard. I had to spend several hours making a C++ program being able to change master volume on Vista.

Broken link? PM me and I'll send you the file!

Link to post
Share on other sites

@Monoceres,

yeah, that'd be way over my head there >_< I didn't mean to minimize Wraithdu's accomplishment, I was just curious since it had been listed as using the COM interface, but as you pointed out, there's 'COM and there is COM' haha. I get the general idea :(

Link to post
Share on other sites

****************************************************************************

* _IsMute_Vista()

*

* Gets the mute state.

****************************************************************************

* _SetMute_Vista()

*

* Sets the mute state.

****************************************************************************

Thanks for this plugin. After moving my laptop to Win7, I haven't had any sort of volume OSD and I've spent the last few days looking for something that doesn't look horrible and actually accurately displays the volume. My question is...what kind of options do you have with _SetMute_Vista? More specifically, can I use it to disable the mute status? I don't know to just raise the volume to "unmute" it, I'd like to have the volume at 50 or whatever, mute it, and then unmute it and have it go back to what it was just so the mute key on my laptop works.

HotKeySet("{VOLUME_MUTE}", "_mute_change")

Func _mute_change()

If _IsMute_Vista = 0 Then

_SetMute_Vista()

Else

???

EndFunc

I'm not sure what goes in that Else to unmute it and set the volume back to what it was when it was muted. I guess I could store the volume as a variable when it's muted, but if there's a way to use _SetMute_Vista to undo it, I'd prefer that way.

As an aside, I also added this to _SetVolume...other people will have to fiddle with the positioning as I moved mine around a bit at the start and then just guessed the 113. Anyway, it sets the numerical volume display to the inverse hex color of the background it's on top of just to make it legible regardless of whether the background is black/white/whatever. I'm sure there's a much better way of doing this, but I'm rusty with my AutoIt stuff, so ridicule away.

$backgroundcolor = PixelGetColor(@DesktopWidth - 8 - 60, @DesktopHeight - $th - 8 - 113)

$inversecolor = "0x" & Hex((16777215 - $backgroundcolor),6)

GuiCtrlSetColor($label, $inversecolor)

Link to post
Share on other sites

My question is...what kind of options do you have with _SetMute_Vista? More specifically, can I use it to disable the mute status?

Wow, I'm an idiot. Just saw the _SetMute_Vista(True) and (False)

I've changed it so I can hit the mute key on my keyboard and it actually mutes the sound and shows the bar at 0, and unmute and have it return to the volume it was when it was muted. Also, changing the volume up or down while it is muted unmutes it and adds/removes 1 to the volume it was before it was muted.

This script works/looks nice enough that I've removed the normal volume icon from the taskbar for good. I'm not sure why volume OSD isn't a global Windows feature. They have a pretty ugly version in Media Center versions, but it seems like something that should be available across the board.

Link to post
Share on other sites

Glad you figured it all out and found it useful. I thought more people would, I use it every day, but I digress.

I'd say more people would jump on this, but a lot of OEM's include (admittedly terrible) versions of this same thing. 90%(made up statistic) of laptop owners probably never install a different OS, and thus never really have a particular need for this. For the ones that do, most end up switching to Linux or a different version of windows where the OEM supplied sound stuff works anyway. For the ones that switch to something that prevents using the real OSD stuff, this is pretty much the only thing that actually works well.

Link to post
Share on other sites
  • 1 month later...

Call me stupid but I can't figure out how to make the OSD volume work.

I have the dll and I have the VC redist files installed. I created a file called osdvol.au3 and copied the text from the example osd code into it. I can run the script but I can't ever see any OSD display.

From the script I see it registers hotkeys for VOLUME_UP and VOLUME_DOWN but what are the physical keys that trigger this?

Exactly how do I use this dll and script?

Link to post
Share on other sites

Ok, I got it to work for me. Apparently my keyboard does not have dedicated volume up/down keys and the volumne knob (alhtough it changes the volume does not invoke the functions) and thus I had to modify the code so that I set hotkeys for volume up/down. I selected ctrl-up and ctrl-down.

Call me stupid but I can't figure out how to make the OSD volume work.

I have the dll and I have the VC redist files installed. I created a file called osdvol.au3 and copied the text from the example osd code into it. I can run the script but I can't ever see any OSD display.

From the script I see it registers hotkeys for VOLUME_UP and VOLUME_DOWN but what are the physical keys that trigger this?

Exactly how do I use this dll and script?

Link to post
Share on other sites
  • 3 months later...

Hello, folks!

I'm afraid I'm doing something stupid, but the sample scripts provided using the plugin "vista_vol.dll" just don't work for me... I'm using AutoIt 3.3.0.0, Windows 7 x64, have installed "Microsoft Visual C++ 2008 SP1 Redistributable" (tried both x86 and x64) and the plugin is on the same script folder, but I'm getting the message "Error: Unknown function name.", which makes me think that the plugin is not being loaded for some reason. Also, I couldn't find any documentation about the function "PluginOpen" in the help file. Any hint for that issue?

Thanks in advance!

Reginald0

Link to post
Share on other sites

If you're on x64, then by default AutoIt runs and compiles 64-bit binaries. The archive contains a 32-bit DLL. You'll have to compile your test scripts as 32-bit in order to successfully load the plugin.

wraithdu, many thanks, you're absolutely right, compiling in 32-bit solved the problem.

By the way, do you experts know if there's some way to execute AutoIt scripts in 32-bit without compiling, even in a 64-bit platform, like Windows 7 x64?

Link to post
Share on other sites

Sure. You can either directly call AutoIt3.exe with the script as an argument, or reinstall AutoIt and tell it to use the 32-bit tools by default (dialog box during install) then you can right-click -> Run Script and it should use the 32-bit version. You could also manually change the registry entry that belongs to that context menu entry to point to AutoIt3.exe.

I've been working a lot with Jos lately on the AutoIt3Wrapper betas, and the next changes will be to reconcile how scripts are run / compiled on the 64-bit platform. Keep an eye on the thread in the Dev forum for updates from him (provided you use Scite4AutoIt3 to write scripts).

Link to post
Share on other sites

Sure. You can either directly call AutoIt3.exe with the script as an argument, or reinstall AutoIt and tell it to use the 32-bit tools by default (dialog box during install) then you can right-click -> Run Script and it should use the 32-bit version. You could also manually change the registry entry that belongs to that context menu entry to point to AutoIt3.exe.

I've been working a lot with Jos lately on the AutoIt3Wrapper betas, and the next changes will be to reconcile how scripts are run / compiled on the 64-bit platform. Keep an eye on the thread in the Dev forum for updates from him (provided you use Scite4AutoIt3 to write scripts).

wraithdu, thanks a lot again. Keep up the good work, you're one of the best out there!

Reginald0

Link to post
Share on other sites
  • 6 months later...

I've modified dll for supporting multiple channel.

i added _GetChannelVolumeLevelScalar_Vista($channel) and _SetChannelVolumeLevelScalar_Vista($channel,$newVolume)

where channel is 0 to 5 int ( 0:left, 1:right, 2:center, 3:sub, 4:behind left, 5:behind right on my soundcard)

/****************************************************************************
* _GetChannelVolumeLevelScalar_Vista()
*
* Returns channel volume level as a scalar value from 0 to 100.
****************************************************************************/

AU3_PLUGIN_DEFINE(_GetChannelVolumeLevelScalar_Vista)
{
    AU3_PLUGIN_VAR  *pMyResult;
    float currentVolume = 0;
    int channel = 0;

    /* Allocate and build the return variable */
    pMyResult = AU3_AllocVar();
    AU3_SetInt32(pMyResult, -1);
    *n_AU3_ErrorCode = 1;

    /* Get channel */
    channel = (int)AU3_GetInt32(&p_AU3_Params[0]);

    if (SUCCEEDED(endpointVolume->GetChannelVolumeLevelScalar(channel,&currentVolume)))
    {
        AU3_SetDouble(pMyResult, (double)(currentVolume * 100));
        *n_AU3_ErrorCode = 0;
    }

    // Pass back the result, error code and extended code.
    *p_AU3_Result       = pMyResult;
    *n_AU3_ExtCode      = 0;

    return AU3_PLUGIN_OK;
}

/****************************************************************************
* _SetChannelVolumeLevelScalar_Vista()
*
* Sets channel volume level as a scalar value from 0 to 100.
****************************************************************************/

AU3_PLUGIN_DEFINE(_SetChannelVolumeLevelScalar_Vista)
{
    AU3_PLUGIN_VAR  *pMyResult;
    float newVolume = 0;
    int channel = 0;

    /* Allocate and build the return variable */
    pMyResult = AU3_AllocVar();
    AU3_SetInt32(pMyResult, -1);
    *n_AU3_ErrorCode = 1;

    /* Get passed volume and channel */
    newVolume = (float)(AU3_GetDouble(&p_AU3_Params[1]) / 100);
    channel = (int)AU3_GetInt32(&p_AU3_Params[0]);

    if (SUCCEEDED(endpointVolume->SetChannelVolumeLevelScalar(channel,newVolume, NULL)))
    {
        AU3_SetInt32(pMyResult, 0);
        *n_AU3_ErrorCode = 0;
    }

    // Pass back the result, error code and extended code.
    *p_AU3_Result       = pMyResult;
    *n_AU3_ExtCode      = 0;

    return AU3_PLUGIN_OK;
}
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.

×
×
  • Create New...