1 usingUnityEngine;2 usingSystem.Runtime.InteropServices;3 usingSystem;4
5 [DisallowMultipleComponent]6 public classSoundManger : MonoBehaviour7 {8 #region System
9 [DllImport("user32.dll")]10 static extern void keybd_event(byte bVk, bytebScan, UInt32 dwFlags, UInt32 dwExtraInfo);11
12 [DllImport("user32.dll")]13 static externByte MapVirtualKey(UInt32 uCode, UInt32 uMapType);14
15 private const byte VK_VOLUME_MUTE = 0xAD;16 private const byte VK_VOLUME_DOWN = 0xAE;17 private const byte VK_VOLUME_UP = 0xAF;18 private const UInt32 KEYEVENTF_EXTENDEDKEY = 0x0001;19 private const UInt32 KEYEVENTF_KEYUP = 0x0002;20
21 ///
22 ///改变系统音量大小,增加23 ///
24 public voidSystemVolumeUp()25 {26 keybd_event(VK_VOLUME_UP, MapVirtualKey(VK_VOLUME_UP, 0), KEYEVENTF_EXTENDEDKEY, 0);27 keybd_event(VK_VOLUME_UP, MapVirtualKey(VK_VOLUME_UP, 0), KEYEVENTF_EXTENDEDKEY | KE