private void Execute_Command_Button_Edit(object Parameter)
        {
            if ((M_Binding)Parameter == null)
            {
                return;
            }

            m_Altes_Binding = (M_Binding)Parameter;

            Hotkey_Edit    = m_Altes_Binding.Bezeichnung;
            AutoEnter_Edit = m_Altes_Binding.AutoEnter;
            for (int i = 0; i < m_Altes_Binding.Auflistung_BindingOptions.Count; i++)
            {
                Command_Edit += m_Altes_Binding.Auflistung_BindingOptions[i].cmd;

                if (i + 1 != m_Altes_Binding.Auflistung_BindingOptions.Count)
                {
                    Command_Edit += "~";
                }
            }

            CurrentKeyValue    = m_Altes_Binding.KeyValue;
            CurrentKeyModValue = m_Altes_Binding.ModValue;

            isEditMode = true;

            _CONTROLLER.SetzeUC(_CONTROLLER.VCustomKeybindsEdit, _CONTROLLER.VMCustomKeybinds);
        }
        private void Execute_Command_Button_Add_Hotkey(object Parameter)
        {
            if (m_Command == null || m_Hotkey == null)
            {
                return;
            }

            if (m_Hotkey.Trim().Length != 0 && m_Hotkey != "BELEGT" && m_Hotkey != "ERROR" && m_Command.Trim().Length != 0)
            {
                // Baue Hotkey und Hotkey Display Objekt
                M_Binding Disp = new M_Binding();
                Disp.Bezeichnung   = m_Hotkey;
                Disp.KeyValue      = CurrentKeyValue;
                Disp.KeyValueForms = (int)(System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey((Key)CurrentKeyValue);
                Disp.ModValue      = CurrentKeyModValue;
                Disp.AutoEnter     = AutoEnter;

                Disp.Auflistung_BindingOptions = new List <M_BindingOption>();

                // Command aufsplitten, wenn Contains ~
                if (m_Command.Contains("~"))
                {
                    if (!AutoEnter)
                    {
                        // Hinweis Anzeigen, wenn Mehrere Commands da sind, aber AutoEnter False ist
                        if (MessageBoxResult.No == Bindermessage.ShowQuestionYesNo("Sie haben den Hotkey mit mehreren Befehlen belegt und die Auto-Enter Funktion deaktiviert!\nBeachten Sie, dass hierdurch nur der letzte Befehl nicht automatisch abgesendet wird!\n\nMöchten Sie den Hotkey trotzdem hinzufügen?"))
                        {
                            return;
                        }
                    }


                    string[] commands = m_Command.Split('~');

                    foreach (string command in commands)
                    {
                        M_BindingOption opt = new M_BindingOption();
                        opt.cmd = command.TrimStart();
                        Disp.Auflistung_BindingOptions.Add(opt);
                    }
                }
                else
                {
                    M_BindingOption opt = new M_BindingOption();
                    opt.cmd = m_Command.TrimStart();
                    Disp.Auflistung_BindingOptions.Add(opt);
                }

                m_Auflistung_Keybinds.Add(Disp);
                OnPropertyChanged("Auflistung_Keybinds");


                // RESET FIELDS
                m_Hotkey  = String.Empty;
                m_Command = String.Empty;

                OnPropertyChanged("Hotkey");
                OnPropertyChanged("Command");
            }
        }
示例#3
0
    public string GetKeyString(M_Binding keybind)
    {
        // INFO
        // Gibt den AHK Hotkey +   ::\r\n    zurück

        /*
         *  PREFIXE
         *  Shift = +
         *  Alt = !
         *  Control = ^
         *
         *
         *
         * */
        string m_AHK = String.Empty;

        int          m_Value = keybind.KeyValue;
        ModifierKeys mod     = (ModifierKeys)keybind.ModValue;

        switch (mod)
        {
        case ModifierKeys.Alt:

            m_AHK += "!";

            foreach (AHKKey key in Enum.GetValues(typeof(AHKKey)))
            {
                // Suche gültigen AHK Key
                if ((int)key == m_Value)
                {
                    if (key.ToString().Contains("Decimal"))
                    {
                        m_AHK += key.ToString().Remove(0, 7);
                    }
                    else
                    {
                        m_AHK += key.ToString();
                    }

                    break;
                }
            }

            break;

        case ModifierKeys.Control:
            m_AHK += "^";

            foreach (AHKKey key in Enum.GetValues(typeof(AHKKey)))
            {
                // Suche gültigen AHK Key
                if ((int)key == m_Value)
                {
                    if (key.ToString().Contains("Decimal"))
                    {
                        m_AHK += key.ToString().Remove(0, 7);
                    }
                    else
                    {
                        m_AHK += key.ToString();
                    }

                    break;
                }
            }
            break;

        case ModifierKeys.Shift:
            m_AHK += "+";

            foreach (AHKKey key in Enum.GetValues(typeof(AHKKey)))
            {
                // Suche gültigen AHK Key
                if ((int)key == m_Value)
                {
                    if (key.ToString().Contains("Decimal"))
                    {
                        m_AHK += key.ToString().Remove(0, 7);
                    }
                    else
                    {
                        m_AHK += key.ToString();
                    }

                    break;
                }
            }

            break;

        case ModifierKeys.None:

            foreach (AHKKey key in Enum.GetValues(typeof(AHKKey)))
            {
                // Suche gültigen AHK Key
                if ((int)key == m_Value)
                {
                    if (key.ToString().Contains("Decimal"))
                    {
                        m_AHK += key.ToString().Remove(0, 7);
                    }
                    else
                    {
                        m_AHK += key.ToString();
                    }

                    break;
                }
            }

            break;
        }

        // Add :: to the string
        m_AHK += "::\r\n";


        return(m_AHK);
    }
        private void LoadKeybinds()
        {
            string m_appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string m_foldername  = "Bonnyfication";

            string m_FileName_Old     = "Keybinds_Store.xml";
            string m_FileNameExtended = "Keybinds_Store_Extended.xml";

            string m_FullpathOld      = Path.Combine(m_appdatapath, m_foldername, m_FileName_Old);
            string m_FullpathExtended = Path.Combine(m_appdatapath, m_foldername, m_FileNameExtended);

            string m_FullFolderPath = Path.Combine(m_appdatapath, m_foldername);


            // C:\Users\Bonnyfication\AppData\Roaming\Bonnyfication_Keybinds.xml
            //Check Folder exists or Create it
            System.IO.Directory.CreateDirectory(m_FullFolderPath);

            // Wenn die alte Keybinder XML besteht auswerten, Convertieren und Löschen
            if (File.Exists(m_FullpathOld))
            {
                //CONVERT AND DELETE
                ObservableCollection <M_Keybind> m_tmp = new ObservableCollection <M_Keybind>();

                try
                {
                    XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Keybind>));
                    using (StreamReader read = new StreamReader(m_FullpathOld))
                    {
                        m_tmp = seri.Deserialize(read) as ObservableCollection <M_Keybind>;
                    }
                }
                catch (Exception ex)
                {
                    Bindermessage.ShowError("Fehler beim Laden der Keybinds!\n\nError:\n" + ex);
                }


                if (m_tmp.Count > 0)
                {
                    m_Auflistung_Keybinds = new ObservableCollection <M_Binding>();

                    foreach (M_Keybind item in m_tmp)
                    {
                        M_Binding bin = new M_Binding();
                        bin.Bezeichnung   = item.Bezeichnung;
                        bin.KeyValue      = item.KeyValue;
                        bin.KeyValueForms = item.KeyValueForms;
                        bin.ModValue      = item.ModValue;
                        bin.AutoEnter     = true;

                        M_BindingOption opt = new M_BindingOption();
                        opt.cmd = item.cmd;

                        bin.Auflistung_BindingOptions = new List <M_BindingOption>();
                        bin.Auflistung_BindingOptions.Add(opt);
                        m_Auflistung_Keybinds.Add(bin);
                    }

                    // Speichere die Bindings im neuen Format

                    try
                    {
                        XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Binding>));
                        using (StreamWriter writ = new StreamWriter(m_FullpathExtended))
                        {
                            seri.Serialize(writ, m_Auflistung_Keybinds);
                        }
                    }
                    catch (Exception ex)
                    {
                        Bindermessage.ShowError("Fehler beim Speichern der konvertierten Keybinds!\n\nError:\n" + ex);
                        Application.Current.Shutdown();
                    }

                    OnPropertyChanged("Auflistung_Keybinds");

                    try
                    {
                        File.Delete(m_FullpathOld);
                    }
                    catch (Exception ex)
                    {
                        Bindermessage.ShowError("Die Datei Keybinder_Store.xml konnte nicht gelöscht werden. Dies ist allerdings erforderlich, damit beim start des Keybinders neue Keybinds nicht überschrieben werden.\nSie können die Datei manuell löschen!\n\nPfad:\n" + m_FullpathOld + "\n\nError:" + ex.Message);
                        Application.Current.Shutdown();
                    }
                }
            }
            else // Existiert die Aktuelle Keybinder_Store_Extended.xml ?
            {
                if (!File.Exists(m_FullpathExtended))
                {
                    return;
                }

                // Auslesen
                Auflistung_Keybinds = new ObservableCollection <M_Binding>();

                try
                {
                    XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Binding>));
                    using (StreamReader read = new StreamReader(m_FullpathExtended))
                    {
                        m_Auflistung_Keybinds = seri.Deserialize(read) as ObservableCollection <M_Binding>;
                    }
                }
                catch (Exception ex)
                {
                    Bindermessage.ShowError("Fehler beim Laden der Keybinds!\n\nError:\n" + ex);
                }

                OnPropertyChanged("Auflistung_Keybinds");
            }
        }