windows 音量調整

2021-10-09 09:35:51 字數 2674 閱讀 6173

1.vbs

set ws = createobject("wscript.shell") '

set oargs = wscript.arguments

if oargs(0) = 0 then

ws.sendkeys chr(&h88ad) '靜音非靜音切bai換

elseif oargs(0) = 1 then

ws.sendkeys chr(&h88ae) '減小音量

elseif oargs(0) = 2 then

ws.sendkeys chr(&h88af) '增大音量88af

elseif oargs(0) = 3 then'音量最大

for i = 1 to 99

ws.sendkeys chr(&h88af)

next

elseif oargs(0) = 4 then'音量最小

for i = 1 to 100

ws.sendkeys chr(&h88ae)

next

elseif oargs(0) = 5 then'音量指定

for i = 1 to 100

ws.sendkeys chr(&h88ae)

next

for i = 1 to oargs(1)/2

ws.sendkeys chr(&h88af)

next

end if

2.模擬鍵盤

3.c++

//2020/9/12

//windwos 音量調整

//參考:

////

#include "pch.h"

#include #include "windows.h "

#include "shellapi.h"

#include "tlhelp32.h"

#include "atlconv.h"

#include #pragma comment(lib, "userenv.lib")

#include #include // volume = 0.500; eg

bool wasapi(float volume, bool isup, bool isdown)

immdeviceenumerator *deviceenumerator = null;

hr = cocreateinstance(__uuidof(mmdeviceenumerator), null, clsctx_inproc_server,

__uuidof(immdeviceenumerator), (lpvoid *)&deviceenumerator);

immdevice *defaultdevice = null;

hr = deviceenumerator->getdefaultaudioendpoint(erender, econsole, &defaultdevice);

if (failed(hr))

deviceenumerator->release();

deviceenumerator = null;

hr = defaultdevice->activate(__uuidof(iaudioendpointvolume), clsctx_inproc_server, null, reinterpret_cast(&m_endpointvolume));

if (failed(hr))

bool currentmute;

hr = m_endpointvolume->getmute(¤tmute);

if (failed(hr))

if (currentmute == true)

float currentvolume;

hr = m_endpointvolume->getmastervolumelevelscalar(¤tvolume); //把主音量的水平標量

if (failed(hr))

std::cout << "current volume is: %f" << currentvolume << std::endl;

if (isup)

hr = m_endpointvolume->setmastervolumelevelscalar(volume, null);

} else if (isdown)

hr = m_endpointvolume->setmastervolumelevelscalar(volume, null);

} else

return true;

}void voicemax()

void voicemin()

void voiceup()

void voicedown()

void voiceset(int volume)

else if (volume < 1)

else

}int main(int argc, char* ar**) else if (strstr(ar**[1], "down") != null)

else

} else

return 1;

}

總結:vbs和模擬鍵盤在桌面互動上可以實現調整系統聲音,c++源**方式可以在系統服務下實現調整系統聲音.

控制windows系統音量

網上有一些控制系統音量的方法 win xp系統可以用mixeropen等方式 win 7系統可以用wsapi等方式 wasapi的全稱是windows audio session api windows音訊會話api 是從windows vista之後引入的 uaa universal audio ...

ubuntu操音量調整命令amixer

1,解除靜音 sudo amixer set master unmute sudo amixer set headphone unmute sudo amixer set front unmute 實際為機箱後面 2,設定音量 amixer c 0 sset master 0 100 80 unmu...

Windows音量變化通知 系統音量監控

總結參考 本次使用win32 api的endpoint volume controls實現當系統音量變化時程式收到通知,環境為win10 64位。實現iaudioendpointvolumecallback介面,重點是onnotify方法。epvolume.h include include inc...