private void btnOK_Click(object sender, EventArgs e) { if (!Helper.stringToKeysArray(tbStopSoundKeys.Text, out Keyboard.Keys[] keysArray, out _)) { keysArray = new Keyboard.Keys[] { } } ; if (loadXMLFilesList.Count == 0 || loadXMLFilesList.All(x => x.Keys.Length > 0 && !string.IsNullOrWhiteSpace(x.XMLLocation) && File.Exists(x.XMLLocation))) { XMLSettings.soundboardSettings.StopSoundKeys = keysArray; XMLSettings.soundboardSettings.LoadXMLFiles = loadXMLFilesList.ToArray(); XMLSettings.soundboardSettings.StartWithWindows = cbStartWithWindows.Checked; Helper.setStartup(XMLSettings.soundboardSettings.StartWithWindows); XMLSettings.soundboardSettings.StartMinimised = cbStartMinimised.Checked; XMLSettings.soundboardSettings.MinimiseToTray = cbMinimiseToTray.Checked; XMLSettings.SaveSoundboardSettingsXML(); this.Close(); } else { MessageBox.Show("One or more entries either have no keys added, the location is empty, or the file the location points to does not exist"); } }
internal static bool stringToKey(string keyString, out Keyboard.Keys key) { if (keyString.Contains("VK_")) { //key has no name keyString = keyString.Substring(keyString.LastIndexOf('_') + 1); try { key = (Keyboard.Keys) int.Parse(keyString, System.Globalization.NumberStyles.HexNumber); return(true); } catch { key = 0; return(false); } } else if (Enum.TryParse(keyString, out key)) { return(true); } else { return(false); } }
internal static bool stringArrayToKeysArray(string[] stringArray, out Keyboard.Keys[] keysArray, out string errorMessage) { errorMessage = ""; if (stringArray == null) { keysArray = new Keyboard.Keys[] { 0 }; return(true); } var keysList = new List <Keyboard.Keys>(); foreach (string keyString in stringArray) { if (stringToKey(keyString, out Keyboard.Keys key)) { keysList.Add(key); } else { errorMessage = "Key string \"" + keyString + "\" doesn't exist"; keysArray = null; return(false); } } keysArray = keysList.ToArray(); return(true); }
public SoundboardSettings(Keyboard.Keys[] stopSoundKeys, LoadXMLFile[] loadXMLFiles, bool startWithWindows, bool startMinimised, bool minimiseToTray, bool enableHotkeys, bool enableLoopback, float soundVolume, bool enableAutoPushToTalk, Keyboard.Keys autoPushToTalkKey, string autoPushToTalkWindow, string lastPlaybackDevice, string lastPlaybackDevice2, string lastLoopbackDevice, string lastXMLFile) { StopSoundKeys = stopSoundKeys; LoadXMLFiles = loadXMLFiles; StartWithWindows = startWithWindows; StartMinimised = startMinimised; MinimiseToTray = minimiseToTray; EnableHotkeys = enableHotkeys; EnableLoopback = enableLoopback; SoundVolume = soundVolume; EnableAutoPushToTalk = enableAutoPushToTalk; AutoPushToTalkKey = autoPushToTalkKey; AutoPushToTalkWindow = autoPushToTalkWindow; LastPlaybackDevice = lastPlaybackDevice; LastPlaybackDevice2 = lastPlaybackDevice2; LastLoopbackDevice = lastLoopbackDevice; LastXMLFile = lastXMLFile; }
private void pushToTalkKeyTimer_Tick(object sender, EventArgs e) { pushToTalkKeyTimer.Interval = 10; //lowering the interval to avoid missing key presses (e.g. when an input is corrected) if (Keyboard.IsKeyDown(Keyboard.Keys.Escape)) { tbPushToTalkKey.Text = ""; pushToTalkKey = default; } else { foreach (Keyboard.Keys key in Enum.GetValues(typeof(Keyboard.Keys))) { if (Keyboard.IsKeyDown(key)) { tbPushToTalkKey.Text = key.ToString(); pushToTalkKey = key; break; } } } }
public void SetKey(Keyboard.Keys key, bool value) { this.keyboard.SetKey(key, value); }
private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbLocation.Text)) { MessageBox.Show("Location is empty"); return; } if (SettingsForm.addingEditingLoadXMLFile && string.IsNullOrWhiteSpace(tbKeys.Text)) { MessageBox.Show("No keys entered"); return; } string[] soundLocations = null; string fileNames; string errorMessage; if (!SettingsForm.addingEditingLoadXMLFile) { if (Helper.stringToFileLocationsArray(tbLocation.Text, out soundLocations, out errorMessage)) { if (soundLocations.Any(x => string.IsNullOrWhiteSpace(x) || !File.Exists(x))) { MessageBox.Show("One or more files do not exist"); this.Close(); return; } } if (soundLocations == null) { MessageBox.Show(errorMessage); return; } } if (!Helper.stringToKeysArray(tbKeys.Text, out Keyboard.Keys[] keysArray, out _)) { keysArray = new Keyboard.Keys[] { } } ; if (SettingsForm.addingEditingLoadXMLFile) { fileNames = Helper.fileLocationsArrayToString(new string[] { tbLocation.Text }); if (editIndex != -1) { settingsForm.lvKeysLocations.Items[editIndex].Text = tbKeys.Text; settingsForm.lvKeysLocations.Items[editIndex].SubItems[1].Text = tbLocation.Text; settingsForm.lvKeysLocations.Items[editIndex].ToolTipText = fileNames; settingsForm.loadXMLFilesList[editIndex].Keys = keysArray; settingsForm.loadXMLFilesList[editIndex].XMLLocation = tbLocation.Text; } else { var item = new ListViewItem(tbKeys.Text); item.SubItems.Add(tbLocation.Text); item.ToolTipText = fileNames; settingsForm.lvKeysLocations.Items.Add(item); settingsForm.loadXMLFilesList.Add(new XMLSettings.LoadXMLFile(keysArray, tbLocation.Text)); } } else { fileNames = Helper.getFileNamesTooltip(soundLocations); string volumeString = vsSoundVolume.Volume == 1 ? "" : Helper.linearVolumeToString(vsSoundVolume.Volume); string windowText = (cbWindows.SelectedIndex > 0) ? cbWindows.Text : ""; if (editIndex != -1) { mainForm.lvKeySounds.Items[editIndex].SubItems[0].Text = tbKeys.Text; mainForm.lvKeySounds.Items[editIndex].SubItems[1].Text = volumeString; mainForm.lvKeySounds.Items[editIndex].SubItems[2].Text = windowText; mainForm.lvKeySounds.Items[editIndex].SubItems[3].Text = tbLocation.Text; mainForm.lvKeySounds.Items[editIndex].ToolTipText = fileNames; mainForm.soundHotkeys[editIndex] = new XMLSettings.SoundHotkey(keysArray, vsSoundVolume.Volume, windowText, soundLocations); } else { var newItem = new ListViewItem(tbKeys.Text); newItem.SubItems.Add(volumeString); newItem.SubItems.Add(windowText); newItem.SubItems.Add(tbLocation.Text); newItem.ToolTipText = fileNames; mainForm.lvKeySounds.Items.Add(newItem); mainForm.soundHotkeys.Add(new XMLSettings.SoundHotkey(keysArray, vsSoundVolume.Volume, windowText, soundLocations)); } mainForm.sortHotkeys(); //remember last used options lastSoundVolume = vsSoundVolume.Volume; lastWindow = cbWindows.Text; } this.Close(); }
public MainForm() { InitializeComponent(); var tooltip = new ToolTip(); tooltip.SetToolTip(btnReloadDevices, "Refresh sound devices"); tooltip.SetToolTip(btnReloadWindows, "Reload windows"); tooltip.SetToolTip(cbPlaybackDevices1, PLAYBACK1_TOOLTIP); tooltip.SetToolTip(cbPlaybackDevices2, PLAYBACK2_TOOLTIP); tooltip.SetToolTip(cbLoopbackDevices, LOOPBACK_TOOLTIP); tooltip.SetToolTip(lblPlayback1, PLAYBACK1_TOOLTIP); tooltip.SetToolTip(lblPlayback2, PLAYBACK2_TOOLTIP); tooltip.SetToolTip(lblLoopback, LOOPBACK_TOOLTIP); tooltip.SetToolTip(vsSoundVolume, SOUND_VOLUME_TOOLTIP); tooltip.SetToolTip(nSoundVolume, SOUND_VOLUME_TOOLTIP); XMLSettings.LoadSoundboardSettingsXML(); //Disable change events for elements that would trigger settings changes and unnecessarily write to settings.xml DisableCheckboxChangeEvents(); DisableSoundVolumeChangeEvents(); loadSoundDevices(false); //false argument keeps device change events disabled Helper.getWindows(cbWindows); Helper.selectWindow(cbWindows, XMLSettings.soundboardSettings.AutoPushToTalkWindow); if (XMLSettings.soundboardSettings.StartMinimised) { this.WindowState = FormWindowState.Minimized; if (XMLSettings.soundboardSettings.MinimiseToTray) { this.HideFormToTray(); } } Helper.setStartup(XMLSettings.soundboardSettings.StartWithWindows); cbEnableHotkeys.Checked = XMLSettings.soundboardSettings.EnableHotkeys; cbEnableLoopback.Checked = XMLSettings.soundboardSettings.EnableLoopback; soundVolume = XMLSettings.soundboardSettings.SoundVolume; vsSoundVolume.Volume = soundVolume; nSoundVolume.Value = Helper.linearVolumeToInteger(vsSoundVolume.Volume); //needed because change events are still disabled pushToTalkKey = XMLSettings.soundboardSettings.AutoPushToTalkKey; tbPushToTalkKey.Text = pushToTalkKey.ToString() == "None" ? "" : pushToTalkKey.ToString(); cbEnablePushToTalk.Checked = XMLSettings.soundboardSettings.EnableAutoPushToTalk; tbPushToTalkKey.Enabled = !cbEnablePushToTalk.Checked; clearHotkey.Enabled = !cbEnablePushToTalk.Checked; if (File.Exists(XMLSettings.soundboardSettings.LastXMLFile)) { //loadXMLFile() returns true if error occurred if (loadXMLFile(XMLSettings.soundboardSettings.LastXMLFile)) { XMLSettings.soundboardSettings.LastXMLFile = ""; XMLSettings.SaveSoundboardSettingsXML(); } } //Add events after settings have been loaded EnableCheckboxChangeEvents(); EnableSoundVolumeChangeEvents(); EnableDeviceChangeEvents(); mainTimer.Enabled = cbEnableHotkeys.Checked; initAudioPlaybackEngine1(); initAudioPlaybackEngine2(); restartLoopback(); //When sound stops, fire event which lets go of push-to-talk key. playbackEngine1.AllInputEnded += OnAllInputEnded; //Don't need to stop holding the push-to-talk key when engine2 stops playing, that's just our in-ear echo. }
private void btnCreateWAV_Click(object sender, EventArgs e) { string[] fileLocation; if (!string.IsNullOrWhiteSpace(tbText.Text)) { //show dialog var diag = new SaveFileDialog(); diag.Filter = "WAV files|*.wav"; if (diag.ShowDialog() == DialogResult.OK) { fileLocation = new string[] { diag.FileName }; } else { return; } } else { MessageBox.Show("No text entered"); return; } //create file synth.SelectVoiceByHints(Gender, VoiceAge.NotSet); synth.SetOutputToWaveFile(fileLocation[0]); PromptBuilder builder = new PromptBuilder(); builder.AppendText(tbText.Text); synth.Speak(builder); synth.Dispose(); synth = null; if (cbAddToList.Checked) { //add to list if (!Helper.stringToKeysArray(tbKeys.Text, out Keyboard.Keys[] keysArray, out _)) { keysArray = new Keyboard.Keys[] { } } ; string windowText = (cbWindows.SelectedIndex > 0) ? cbWindows.Text : ""; mainForm.soundHotkeys.Add(new XMLSettings.SoundHotkey(keysArray, vsSoundVolume.Volume, windowText, fileLocation)); var newItem = new ListViewItem(tbKeys.Text); newItem.SubItems.Add(vsSoundVolume.Volume == 1 ? "" : Helper.linearVolumeToString(vsSoundVolume.Volume)); newItem.SubItems.Add(windowText); newItem.SubItems.Add(fileLocation[0]); newItem.ToolTipText = Helper.getFileNamesTooltip(fileLocation); mainForm.lvKeySounds.Items.Add(newItem); mainForm.sortHotkeys(); //remember last used options lastWindow = cbWindows.Text; lastSoundVolume = vsSoundVolume.Volume; } //remember last used options lastGenderIndex = cbGender.SelectedIndex; lastAddToListChecked = cbAddToList.Checked; MessageBox.Show("Saved: " + fileLocation[0]); }