Exemplo n.º 1
0
        private void ToggleShortcut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            e.Handled = true;
            var    converter      = new KeysConverter();
            string modifierString = converter.ConvertToString(e.KeyboardDevice.Modifiers);
            string key            = converter.ConvertToString(e.Key);

            // Supress unwanted keys
            if (key == "LeftCtrl" || key == "RightCtrl" || key == "LeftShift" || key == "RightShift" || key == "System" || key == "LWin" || key == "RWin")
            {
                key = "";
            }
            System.Windows.Controls.TextBox textbox = (System.Windows.Controls.TextBox)sender;

            switch (textbox.Name)
            {
            case "toggleShortcutBox":
                toggleKeyboardShortcut = new KBShortcut("Toggle Lights", e.KeyboardDevice.Modifiers, e.Key);
                textbox.Text           = toggleKeyboardShortcut.description;
                break;

            case "brightnessUpShortcut":
                increaseBrightnessShortcut = new KBShortcut("Brightness Up", e.KeyboardDevice.Modifiers, e.Key);
                textbox.Text = increaseBrightnessShortcut.description;
                break;

            case "brightnessDownShortcut":
                decreaseBrightnessShortcut = new KBShortcut("Brightness Down", e.KeyboardDevice.Modifiers, e.Key);
                textbox.Text = decreaseBrightnessShortcut.description;
                break;
            }
        }
Exemplo n.º 2
0
        public static void WriteShortcutToFile(KBShortcut key)
        {
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            File.WriteAllText(@directory + key.name, Serialize(key));
        }
Exemplo n.º 3
0
 private void RestoreKeyboardShortcuts()
 {
     // Restore the keyboard shortcuts
     toggleKeyboardShortcut = SetKeyboardShortcut(Settings.restoreSetting <KBShortcut>("Toggle Lights"),
                                                  ToggleLightsKeyPress, "Toggle Lights", ModifierKeys.Shift, Key.F1, toggleShortcutBox);
     increaseBrightnessShortcut = SetKeyboardShortcut(Settings.restoreSetting <KBShortcut>("Brightness Up"),
                                                      IncreaseBrightnessKeyPress, "Brightness Up", ModifierKeys.Shift, Key.F3, brightnessUpShortcut);
     decreaseBrightnessShortcut = SetKeyboardShortcut(Settings.restoreSetting <KBShortcut>("Brightness Down"),
                                                      DecreaseBrightnessKeyPress, "Brightness Down", ModifierKeys.Shift, Key.F2, brightnessDownShortcut);
 }
Exemplo n.º 4
0
        private KBShortcut SetKeyboardShortcut(KBShortcut shortcut, EventHandler <HotkeyEventArgs> handler, string name, ModifierKeys default_modifiers,
                                               Key default_key, System.Windows.Controls.TextBox textbox)
        {
            shortcut = Settings.restoreSetting <KBShortcut>(name);
            if (shortcut == null)
            {
                shortcut = new KBShortcut(name, default_modifiers, default_key);
            }
            HotkeyManager.Current.AddOrReplace(name, shortcut.key, shortcut.modifiers, handler);
            textbox.Text = shortcut.description;

            return(shortcut);
        }
Exemplo n.º 5
0
 private void ChangeShortcutButton(string name, string description, EventHandler <HotkeyEventArgs> handler, KBShortcut shortcut)
 {
     HotkeyManager.Current.AddOrReplace(name, shortcut.key, shortcut.modifiers, handler);
     System.Windows.MessageBox.Show(description + shortcut.description);
     Settings.WriteShortcutToFile(toggleKeyboardShortcut);
 }