예제 #1
0
        public SettingViewModel()
        {
            Key          key      = (Key)Properties.Settings.Default.EnumKey;
            ModifierKeys modifier = (ModifierKeys)Properties.Settings.Default.EnumModifierKeys;

            ShortcutKey.Value = key.ToString();

            ModifierShift.Value   = modifier.HasFlag(ModifierKeys.Shift);
            ModifierAlt.Value     = modifier.HasFlag(ModifierKeys.Alt);
            ModifierCtrl.Value    = modifier.HasFlag(ModifierKeys.Control);
            ModifierWindows.Value = modifier.HasFlag(ModifierKeys.Windows);

            GHKeyString.Value = HotKeyManager.GetGHKeyString();
        }
예제 #2
0
        public void SetGlobalHotkey()
        {
            ModifierKeys modifier = ModifierShift.Value ? ModifierKeys.Shift : ModifierKeys.None;

            modifier |= ModifierAlt.Value ? ModifierKeys.Alt : ModifierKeys.None;
            modifier |= ModifierCtrl.Value ? ModifierKeys.Control : ModifierKeys.None;
            modifier |= ModifierWindows.Value ? ModifierKeys.Windows : ModifierKeys.None;

            if (Enum.TryParse <Key>(ShortcutKey.Value, out Key key))
            {
                if (HotKeyManager.RegisterHotKey(modifier, key))
                {
                    GHKeyString.Value = HotKeyManager.GetGHKeyString();

                    Message.Value = "ショートカットキーを更新しました";
                }
            }
            else
            {
                Message.Value = "キーの記述が不正です。";
            }
        }