コード例 #1
0
        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();
            }
        }
コード例 #2
0
        private void OnSetKey(object sender, RoutedEventArgs e)
        {
            string KeyBindText = ((TextBox)this.FindName("Keybind")).Text;
            string MeanText    = ((TextBox)this.FindName("MeanTextBox")).Text;
            string SigmaText   = ((TextBox)this.FindName("SigmaTextBox")).Text;

            if (KeyBindText.Trim().Length == 0 || KeyBindText.Equals("None"))
            {
                MessageBox.Show("Please set your key bind first", "No key bind detected", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if (MeanText.EndsWith(".") || SigmaText.EndsWith("."))
            {
                MessageBox.Show("Please type in the seconds between each click", "Invalid number format", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            double Mean  = double.Parse(MeanText);
            double Sigma = double.Parse(SigmaText);

            if (Mean.Equals(0f))
            {
                MessageBox.Show("The time between clicks cannot be 0", "Invalid number format", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            bool leftClick  = ((ComboBox)this.FindName("ClickOption")).SelectedIndex == 0;
            Key  newKeyBind = KeyUtil.ConvertStringToKey(KeyBindText);

            Config.Instance.Key       = newKeyBind;
            Config.Instance.Mean      = Mean;
            Config.Instance.Sigma     = Sigma;
            Config.Instance.LeftClick = leftClick;
            Configuration manager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection appSetting = manager.AppSettings.Settings;

            appSetting["keybind"].Value     = ((int)Config.Instance.Key).ToString();
            appSetting["mean"].Value        = Config.Instance.Mean.ToString(CultureInfo.InvariantCulture);
            appSetting["sigma"].Value       = Config.Instance.Sigma.ToString(CultureInfo.InvariantCulture);
            appSetting["clickOption"].Value = Config.Instance.LeftClick ? "left" : "right";
            manager.Save(ConfigurationSaveMode.Full);
            ConfigurationManager.RefreshSection(manager.AppSettings.SectionInformation.Name);
            MessageBox.Show("Settings applied", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            RefreshEstimate();
        }
コード例 #3
0
 private void OnNewKeybind(object sender, KeyEventArgs e)
 {
     ((TextBox)sender).Text = KeyUtil.ConvertKeyToString(e.Key);
     e.Handled = true;
 }