|
3 | 3 | using GlobalHotKeys; |
4 | 4 | using GlobalHotKeys.Native.Types; |
5 | 5 | using System.Runtime.InteropServices; |
| 6 | +using Microsoft.Toolkit.Uwp.Notifications; |
6 | 7 |
|
7 | 8 | internal class Program |
8 | 9 | { |
9 | 10 | private static void Main() => new Program().MainAsync().GetAwaiter().GetResult(); |
10 | 11 |
|
11 | 12 | private async Task MainAsync() |
12 | 13 | { |
13 | | - Console.WriteLine("Starting"); |
14 | | - await Task.Delay(2000); |
15 | | - |
16 | | - _ = NativeMethods.FreeConsole(); |
17 | 14 | HideConsoleWindow(); |
18 | 15 |
|
19 | 16 | using var hotKeyManager = new HotKeyManager(); |
20 | 17 | using var subscription = hotKeyManager.HotKeyPressed.Subscribe(HotKeyPressed); |
21 | | - using var shift1 = hotKeyManager.Register(VirtualKeyCode.VK_F1, Modifiers.Control); |
| 18 | + _ = hotKeyManager.Register(VirtualKeyCode.VK_F1, Modifiers.Control); |
| 19 | + _ = hotKeyManager.Register(VirtualKeyCode.VK_F2, Modifiers.Control); |
| 20 | + _ = hotKeyManager.Register(VirtualKeyCode.VK_F3, Modifiers.Control); |
22 | 21 |
|
23 | 22 | void HotKeyPressed(HotKey hotKey) |
24 | 23 | { |
25 | 24 | var processId = this.GetActiveWindowProcessId(); |
26 | 25 | var soundDevice = this.GetSoundDevice(processId); |
27 | 26 |
|
28 | 27 | if (soundDevice != null) |
29 | | - soundDevice.SimpleAudioVolume.Mute = !soundDevice.SimpleAudioVolume.Mute; |
| 28 | + { |
| 29 | + if (hotKey.Key == VirtualKeyCode.VK_F1 && hotKey.Modifiers == Modifiers.Control) |
| 30 | + { |
| 31 | + |
| 32 | + soundDevice.SimpleAudioVolume.Mute = !soundDevice.SimpleAudioVolume.Mute; |
| 33 | + |
| 34 | + new ToastContentBuilder() |
| 35 | + .SetToastScenario(ToastScenario.Default) |
| 36 | + .SetToastDuration(ToastDuration.Short) |
| 37 | + .AddText($"ℹ️ {(soundDevice.SimpleAudioVolume.Mute ? "Muted" : "Unmuted")} '{soundDevice.DisplayName}'") |
| 38 | + .Show(); |
| 39 | + } |
| 40 | + else if (hotKey.Key == VirtualKeyCode.VK_F2 && hotKey.Modifiers == Modifiers.Control) |
| 41 | + { |
| 42 | + if (soundDevice.SimpleAudioVolume.Volume - 0.05f >= 0) |
| 43 | + { |
| 44 | + Console.WriteLine(soundDevice.SimpleAudioVolume.Volume - 0.05f); |
| 45 | + soundDevice.SimpleAudioVolume.Volume = soundDevice.SimpleAudioVolume.Volume - 0.05f; |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + Console.WriteLine(0f); |
| 50 | + soundDevice.SimpleAudioVolume.Volume = 0f; |
| 51 | + } |
| 52 | + } |
| 53 | + else if (hotKey.Key == VirtualKeyCode.VK_F3 && hotKey.Modifiers == Modifiers.Control) |
| 54 | + { |
| 55 | + if (soundDevice.SimpleAudioVolume.Volume + 0.05f <= 1) |
| 56 | + { |
| 57 | + Console.WriteLine(soundDevice.SimpleAudioVolume.Volume + 0.05f); |
| 58 | + soundDevice.SimpleAudioVolume.Volume = soundDevice.SimpleAudioVolume.Volume + 0.05f; |
| 59 | + } |
| 60 | + else |
| 61 | + { |
| 62 | + Console.WriteLine(1f); |
| 63 | + soundDevice.SimpleAudioVolume.Volume = 1f; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
30 | 67 | } |
31 | 68 |
|
32 | 69 | await Task.Delay(-1); |
33 | 70 | } |
34 | 71 |
|
35 | 72 | private static void HideConsoleWindow() |
36 | 73 | { |
| 74 | + _ = NativeMethods.FreeConsole(); |
37 | 75 | IntPtr hWnd = NativeMethods.GetConsoleWindow(); |
38 | 76 | _ = NativeMethods.ShowWindow(hWnd, NativeMethods.SW_HIDE); |
39 | 77 | } |
|
0 commit comments