Ejemplo n.º 1
0
        public void SetHotkey(string keyStr, bool triggerValidate = true)
        {
            tbMsg.Visibility = Visibility.Visible;
            tbHotkey.Text = keyStr;
            tbHotkey.Select(tbHotkey.Text.Length, 0);
            CurrentHotkey = new HotkeyModel(keyStr);

            if (triggerValidate)
            {
                CurrentHotkeyAvailable = CheckHotAvailabel(CurrentHotkey);
                if (!CurrentHotkeyAvailable)
                {
                    tbMsg.Foreground = new SolidColorBrush(Colors.Red);
                    tbMsg.Text = "hotkey unavailable";
                }
                else
                {
                    tbMsg.Foreground = new SolidColorBrush(Colors.Green);
                    tbMsg.Text = "succeed";
                }
                OnOnHotkeyChanged();
            }
        }
Ejemplo n.º 2
0
 public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
 {
     var hotkey = new HotkeyModel(hotkeyStr);
     try {
         HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
     }
     catch (Exception) {
         MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
     }
 }
Ejemplo n.º 3
0
        private bool CheckHotAvailabel(HotkeyModel hotkey)
        {
            try
            {
                HotkeyManager.Current.AddOrReplace("HotkeyAvailableTest", hotkey.CharKey, hotkey.ModifierKeys, OnHotkey);

                return true;
            }
            catch
            {
            }
            finally
            {
                HotkeyManager.Current.Remove("HotkeyAvailableTest");
            }

            return false;
        }