static int Main(string[] args) { if (args.Length == 1) { if (args[0] == RegMapCapsLock.CommandMap) { RegMapCapsLock.SetCommandLine(); } if (args[0] == RegMapCapsLock.CommandReset) { RegMapCapsLock.ResetCommandLine(); } return(0); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (var context = new NotifyIconContext()) using (var level = new LevelWatcher()) using (var hotkey = new GlobalHotKey()) using (var timer = new MuteTimer()) using (var keymon = new KeyMonitoring()) { Application.Run(context); return(0); } }
void Run() { try { NotifyIconContext.ToolTip("Starting controller"); using (var ctrl = new CoreAudioController()) { audio = ctrl; //NotifyIconContext.Info(1000, "Active", "Forcing all capture levels to " + Level + "%"); NotifyIconContext.Level(ConfigManager.Target); while (true) { UpdateLevel(reportFix: true); Thread.Sleep(1000); } } } catch (ThreadAbortException) { //Silent exit } catch (Exception ex) { NotifyIconContext.Error(60000, ex.GetType().Name, ex.Message); Thread.Sleep(60000); Application.Exit(); } }
void RegisterHotKey(ModifierKeys mod, Keys key) { currentId++; if (!RegisterHotKey(Handle, currentId, (uint)mod, (uint)key)) { NotifyIconContext.Error(10000, "HotKey Error", "Failed to register hotkey " + mod + " + " + key); } }
static void UpdateLevel(CoreAudioDevice dev, bool reportFix) { var target = ConfigManager.Target; var orig = dev.IsMuted ? 0 : dev.Volume; if (orig != target) { dev.Mute(target == 0); if (target != 0) { dev.Volume = target; } if (reportFix && ConfigManager.ShowNotifications) { NotifyIconContext.Warning(5000, "Forced level " + orig + " --> " + target + " %", dev.FullName); } } }