コード例 #1
0
ファイル: HotkeyControl.xaml.cs プロジェクト: dstiert/bloop
        public void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
        {
            CurrentHotkey = keyModel;

            tbHotkey.Text = CurrentHotkey.ToString();
            tbHotkey.Select(tbHotkey.Text.Length, 0);

            if (triggerValidate)
            {
                CurrentHotkeyAvailable = CheckHotkeyAvailability();
                if (!CurrentHotkeyAvailable)
                {
                    tbMsg.Foreground = new SolidColorBrush(Colors.Red);
                    tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
                }
                else
                {
                    tbMsg.Foreground = new SolidColorBrush(Colors.Green);
                    tbMsg.Text = InternationalizationManager.Instance.GetTranslation("succeed");
                }
                tbMsg.Visibility = Visibility.Visible;
                OnHotkeyChanged();
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: dstiert/bloop
 public void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs> action)
 {
     string hotkeyStr = hotkey.ToString();
     try
     {
         HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
     }
     catch (Exception)
     {
         string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
         MessageBox.Show(errorMsg);
     }
 }
コード例 #3
0
ファイル: HotkeyControl.xaml.cs プロジェクト: dstiert/bloop
        void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            tbMsg.Visibility = Visibility.Hidden;

            //when alt is pressed, the real key should be e.SystemKey
            Key key = (e.Key == Key.System ? e.SystemKey : e.Key);

            SpecialKeyState specialKeyState = GlobalHotkey.Instance.CheckModifiers();

            var hotkeyModel = new HotkeyModel(
                specialKeyState.AltPressed,
                specialKeyState.ShiftPressed,
                specialKeyState.WinPressed,
                specialKeyState.CtrlPressed,
                key);

            var hotkeyString = hotkeyModel.ToString();

            if (hotkeyString == tbHotkey.Text)
            {
                return;
            }

            Dispatcher.DelayInvoke("HotkeyAvailabilityTest",
                o =>
                {
                    SetHotkey(hotkeyModel);
                },
                TimeSpan.FromMilliseconds(500));
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: dstiert/bloop
 public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
 {
     var hotkey = new HotkeyModel(hotkeyStr);
     SetHotkey(hotkey, action);
 }