public void LoadDevices() { DeviceOutBox.Items.Clear(); DeviceOutBox.Items.AddRange(SoundSystem.PopulateOutputDevices()); DeviceInBox.Items.Clear(); DeviceInBox.Items.AddRange(SoundSystem.PopulateInputDevices()); if (Config.CurrentConfig.CurrentOutputDevice >= DeviceOutBox.Items.Count) { Config.CurrentConfig.CurrentOutputDevice = DeviceOutBox.Items.Count - 1; } if (Config.CurrentConfig.CurrentInputDevice >= DeviceInBox.Items.Count) { Config.CurrentConfig.CurrentInputDevice = DeviceInBox.Items.Count - 1; } DeviceOutBox.SelectedIndex = Config.CurrentConfig.CurrentOutputDevice; DeviceInBox.SelectedIndex = Config.CurrentConfig.CurrentInputDevice; SoundSystem.resetListener(); }
public MainForm() { InitializeComponent(); _FILELOCK = false; _NEWLINES = Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine; btnList = new List <BindingButton>(); _currentForm = this; KeyListener._hookID = KeyListener.SetHook(KeyListener._proc); KeyListener._listenerEnabled = true; Overlay overlay = new Overlay(); overlay.UpdateBehaviorText(); RenderCanvas(); SoundSystem.PopulateOutputDevices(); Thread t = new Thread(SoundSystem.ContinuousInputPlayback); t.Start(); SoundSystem.InitializeStoppables(); }
public void ToggleSystemEnabled(Button btn) { if (btn == null) { btn = (Button)Controls.Find("btnToggleSystem", false).First(); } KeyListener._listenerEnabled = !KeyListener._listenerEnabled; btn.Text = KeyListener._listenerEnabled == true ? "Sound Enabled" : "Sound Muted"; btn.BackColor = KeyListener._listenerEnabled == true ? Color.Green : Color.PaleVioletRed; if (KeyListener._listenerEnabled == false) { SoundSystem.KillAllSounds(); if (Config.CurrentConfig.MuteInputWithSoundSystem) { SoundSystem.InputDisabled = true; } } else { SoundSystem.InputDisabled = false; } //ToggleInputDevices(_systemEnabled); }
public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { int vkCode = Marshal.ReadInt32(lParam); if (!_listenerEnabled && !changeBinding && vkCode != Config.CurrentConfig.ToggleSystemBinding) { return(CallNextHookEx(_hookID, nCode, wParam, lParam)); } if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { if (changeBinding) { if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleOverlay) { Config.CurrentConfig.ToggleOverlayBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleProfile) { Config.CurrentConfig.ToggleProfileBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleSystem) { Config.CurrentConfig.ToggleSystemBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleMode) { Config.CurrentConfig.ToggleModeBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.Record) { Config.CurrentConfig.RecordBinding = vkCode; } else { for (int i = 0; i < SoundProfile.CurrentSoundProfile.Bindings.Length; i++) { int tempCode = SoundProfile.CurrentSoundProfile.Bindings[i]; if (tempCode == vkCode && SetBindingForm._currentForm.CurrentButton != i) { SoundProfile.CurrentSoundProfile.Bindings[i] = 0; SetBindingForm._currentForm.RemovedBinding = i; break; } SoundProfile.CurrentSoundProfile.Bindings[SetBindingForm._currentForm.CurrentButton] = vkCode; SoundProfile.CurrentSoundProfile.SaveSoundProfile(); } } //Set new binding SetBindingForm._currentForm.NewBindingSet = true; SetBindingForm._currentForm.Close(); return((System.IntPtr) 1); } else { if (vkCode == Config.CurrentConfig.ToggleOverlayBinding) { if (Overlay._currentOverlay.Visible) { Overlay._currentOverlay.Hide(); } else { Overlay._currentOverlay.Show(); } return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.ToggleProfileBinding) { SoundProfile.Next(); return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.ToggleSystemBinding) { MainForm._currentForm.ToggleSystemEnabled(null); Overlay._currentOverlay.UpdateStatusColor(); return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.ToggleModeBinding) { SoundSystem.KillAllSounds(); SoundSystem.SwitchSoundMode(); if (SettingsForm._currentForm != null) { SettingsForm._currentForm.SetKeyPressBoxSelectedIndex(); } return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.RecordBinding) //Control button on keyboard { isRecording = true; //Enables recording } else if (!isRecording) { if (SoundSystem.PlaySound(Utilities.ConvertKeyCodeToButtonId(vkCode))) { if (Config.CurrentConfig.InterruptKeys) { return((System.IntPtr) 1); } } } else { if (SoundSystem.RecordSound(Utilities.ConvertKeyCodeToButtonId(vkCode))) { if (Config.CurrentConfig.InterruptKeys) { return((System.IntPtr) 1); } } } } } else if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP) { if (vkCode == Config.CurrentConfig.RecordBinding) //Control button on keyboard { isRecording = false; SoundSystem.StopRecording(); //if ctrl is released stop all recording } } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
//Save on close window private void Form1_FormClosing(object sender, FormClosingEventArgs e) { SoundSystem.KillInputListener(); }
//eventhandler to play the sound private void ButtonClickPlay(object o, EventArgs e) { SoundSystem.PlaySound(Convert.ToInt16(((Button)o).Name.Substring(3))); }