private void ReadConfig() { try { Configuration manager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection appSetting = manager.AppSettings.Settings; if (appSetting["keybind"] == null || appSetting["mean"] == null || appSetting["sigma"] == null || appSetting["clickOption"] == null) { InitConfig(); } Config.Instance.Key = (Key)int.Parse(appSetting["keybind"].Value); Config.Instance.Mean = double.Parse(appSetting["mean"].Value); Config.Instance.Sigma = double.Parse(appSetting["sigma"].Value); if (!appSetting["clickOption"].Value.Equals("left") && !appSetting["clickOption"].Value.Equals("right")) { throw new InvalidConstraintException("Invalid config value in clickOption"); } Config.Instance.LeftClick = appSetting["clickOption"].Value.Equals("left"); ((TextBox)this.FindName("Keybind")).Text = KeyUtil.ConvertKeyToString(Config.Instance.Key); ((TextBox)this.FindName("MeanTextBox")).Text = Config.Instance.Mean.ToString(CultureInfo.InvariantCulture); ((TextBox)this.FindName("SigmaTextBox")).Text = Config.Instance.Sigma.ToString(CultureInfo.InvariantCulture); ((ComboBox)this.FindName("ClickOption")).SelectedIndex = Config.Instance.LeftClick ? 0 : 1; } catch (Exception) { InitConfig(); } }
private void OnNewKeybind(object sender, KeyEventArgs e) { ((TextBox)sender).Text = KeyUtil.ConvertKeyToString(e.Key); e.Handled = true; }