//Turns on media_player if not already on and if set to do so in settings. void StartupCommands() { if (Properties.Settings.Default.AutoOn) { if (HAData["state"] == "off") { Task.Factory.StartNew(() => HAAPI.Power()); } } if (Properties.Settings.Default.AutoOnSource) { Task.Factory.StartNew(() => HAAPI.Set_Input(Properties.Settings.Default.OnInput)); } if (!String.IsNullOrEmpty(Properties.Settings.Default.StartSwitch)) { Task.Factory.StartNew(() => HAAPI.Toggle_Switch("turn_on", Properties.Settings.Default.StartSwitch)); } if (!String.IsNullOrEmpty(Properties.Settings.Default.ExtraApplication)) { Process.Start(Properties.Settings.Default.ExtraApplication, Properties.Settings.Default.ExtraApplicationArgs); } }
//If left click show context menu with all available HA sources, if right click automatically change to OnInput. private void imgInput_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: contextSources.Show(this, imgInput.Location, ToolStripDropDownDirection.BelowRight); break; case MouseButtons.Right: Task.Factory.StartNew(() => HAAPI.Set_Input()); break; } }
//Turns off media_player if not already off and if set to do so in settings. void ShutdownCommands() { if (Properties.Settings.Default.AutoOffSource) { if (HAData["state"] == "on") { Task.Factory.StartNew(() => HAAPI.Set_Input(Properties.Settings.Default.OffInput)); } } if (Properties.Settings.Default.AutoOff) { if (HAData["state"] == "on") { Task.Factory.StartNew(() => HAAPI.Power()); } } if (!String.IsNullOrEmpty(Properties.Settings.Default.StopSwitch)) { Task.Factory.StartNew(() => HAAPI.Toggle_Switch("turn_off", Properties.Settings.Default.StopSwitch)); } }
// Handle the Global Keybinds. private void _globalHook_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { //Continue only if CTRL wasn't pressed. if (e.Modifiers != System.Windows.Forms.Keys.Control) { switch (e.KeyCode) { case System.Windows.Forms.Keys.VolumeUp: e.Handled = true; Task.Factory.StartNew(() => HAAPI.Volume_Up()); if (Properties.Settings.Default.OSD && this.Opacity == 0) { Task.Factory.StartNew(() => ShowOSD()); } break; case System.Windows.Forms.Keys.VolumeDown: e.Handled = true; Task.Factory.StartNew(() => HAAPI.Volume_Down()); if (Properties.Settings.Default.OSD && this.Opacity == 0) { Task.Factory.StartNew(() => ShowOSD()); } break; case System.Windows.Forms.Keys.VolumeMute: if (!Properties.Settings.Default.DisableMute) { e.Handled = true; bool state = HAData["attributes"]["is_volume_muted"]; Task.Factory.StartNew(() => HAAPI.Volume_Mute(state)); } break; // Pressing the Pause key without Shift will toggle power, with Shift it changes to the OnInput. case System.Windows.Forms.Keys.Pause: e.Handled = true; if (e.Modifiers == System.Windows.Forms.Keys.Shift) { Task.Factory.StartNew(() => HAAPI.Set_Input()); } else { Task.Factory.StartNew(() => HAAPI.Power()); } break; // Pressing the Scroll key without Shift will turn on additional switch, with Shift it turns off additional switch. case System.Windows.Forms.Keys.Scroll: e.Handled = true; if (e.Modifiers == System.Windows.Forms.Keys.Shift) { Task.Factory.StartNew(() => HAAPI.Toggle_Switch("turn_off", Properties.Settings.Default.StopSwitch)); } else { Task.Factory.StartNew(() => HAAPI.Toggle_Switch("turn_on", Properties.Settings.Default.StartSwitch)); } break; default: break; } } }
//This is a workaround to be able to add seperate events to each dynamic context menu entry (source). void contextsource(object sender, EventArgs e) => Task.Factory.StartNew(() => HAAPI.Set_Input(sender.ToString()));