예제 #1
0
 public static int GetProcessIDByName(string name)
 {
     foreach (var process in AppVolumeController.GetAudioProcesses())
     {
         //Console.WriteLine(String.Format("id: {0} | name: {1} | title: {2}", process.Id, process.ProcessName, process.MainWindowTitle));
         if (process.ProcessName == name)
         {
             return(process.Id);
         }
     }
     return(-1);
 }
예제 #2
0
        static void Main(string[] args)
        {
            Powermate a = new Powermate();

            a.processName = "vivaldi";
            a.processId   = AppVolumeController.GetProcessIDByName(a.processName);

            a.OnPress += (powermate) => {
                bool?muted = AppVolumeController.ToggleApplicationMute(powermate.processId);
                if (muted == null)
                {
                    powermate.processId = AppVolumeController.GetProcessIDByName(powermate.processName);
                    AppVolumeController.ToggleApplicationMute(powermate.processId);
                }
            };

            a.OnLeft += (powermate) =>
            {
                if (!AppVolumeController.StepVolumeByProcessId(powermate.processId, -2f))
                {
                    powermate.processId = AppVolumeController.GetProcessIDByName(powermate.processName);
                }
            };

            a.OnRight += (powermate) =>
            {
                if (!AppVolumeController.StepVolumeByProcessId(powermate.processId, 2f))
                {
                    powermate.processId = AppVolumeController.GetProcessIDByName(powermate.processName);
                }
            };

            blePowermates.Add("00:12:92:08:2b:c8", a);

            StartBleDeviceWatcher();

            Console.ReadKey();

            StopBleDeviceWatcher();
        }