Beispiel #1
0
 public void AddKey(Key k)
 {
     if (!HotKeys.ContainsKey(k.KeyName))
     {
         HotKeys.Add(k.KeyName, k);
     }
 }
Beispiel #2
0
        public static void RegisterHotKey(CaptureMode mode)
        {
            if (Handle == IntPtr.Zero)
            {
                return;
            }
            if (!HotKeys.ContainsKey(mode))
            {
                return;
            }

            var hotKey = HotKeys[mode];

            if (hotKey == null)
            {
                return;
            }

            if (hotKey.IsRegistered)
            {
                UnregisterHotKey(mode);
            }

            if (hotKey.Modifiers == WindowNative.KeyModifiers.None && hotKey.Key == Keys.None)
            {
                return;
            }

            if (WindowNative.RegisterHotKey(Handle, (int)mode, hotKey.Modifiers, hotKey.Key))
            {
                hotKey.IsRegistered = true;
            }
        }
Beispiel #3
0
        /// <inheritdoc />
        public override void UnregisterHotKey(VirtualKeys key, Modifiers modifiers)
        {
            // remove no repeat before adding to list to avoid getting different hash
            modifiers = (Modifiers)((uint)modifiers & 0xF);

            KeyModifierCombination combination = new KeyModifierCombination(key, modifiers);

            if (!HotKeys.ContainsKey(combination))
            {
                String error = $"Failed to unregister hotKey : HotKey \"{key}+{modifiers}\" is not registered";
                Logger.Warn(error);
                throw new HotKeyException(error);
            }

            try
            {
                HotKey tmpHotKey = HotKeys[combination];
                tmpHotKey.UnregisterHotKey();
                HotKeysId.Remove(tmpHotKey.Id);
                HotKeys.Remove(combination);
            }
            catch (HotKeyException e)
            {
                Logger.Warn("Failed to unregister hotKey : {0}", e.Message);
                throw;
            }
        }
Beispiel #4
0
        private static void SetDefault()
        {
            if (string.IsNullOrWhiteSpace(CaptureSaveDirectory) || !Directory.Exists(CaptureSaveDirectory))
            {
                CaptureSaveDirectory = Path.Combine(Application.StartupPath, "Capture");
            }
            if (string.IsNullOrWhiteSpace(SaveImageFormat))
            {
                SaveImageFormat = ImageFormats[0];
            }
            if (GifFPS == 0)
            {
                GifFPS = 15;
            }
            if (VideoFPS == 0)
            {
                VideoFPS = 30;
            }
            if (string.IsNullOrWhiteSpace(AudioSource))
            {
                AudioSource = FFmpeg.DefaultAudioSource;
            }
            if (string.IsNullOrWhiteSpace(RecordSaveDirectory) || !Directory.Exists(RecordSaveDirectory))
            {
                RecordSaveDirectory = Path.Combine(Application.StartupPath, "Capture");
            }

            if (HotKeys == null)
            {
                HotKeys = new Dictionary <CaptureMode, HotKey>();
            }
            foreach (CaptureMode mode in Enum.GetValues(typeof(CaptureMode)))
            {
                if (!HotKeys.ContainsKey(mode))
                {
                    HotKeys.Add(mode, HotKey.CreateDefault(mode));
                    RegisterHotKey(mode);
                }
            }

            // 설정된 핫키 등록
            foreach (var mode in HotKeys.Keys)
            {
                RegisterHotKey(mode);
            }

            if (EditLineColor == Color.Empty)
            {
                EditLineColor = Color.Red;
            }
            if (EditLineSize == 0)
            {
                EditLineSize = 10;
            }
        }
		internal HotKeySettingWindow(DoubanFMWindow owner, HotKeys hotKeys)
		{
			InitializeComponent();

			HotKeys = hotKeys;
            foreach (var child in HotKeysGrid.Children)
			{
				if (child is HotKeySettingControl)
				{
					HotKeySettingControl setting = child as HotKeySettingControl;
					if (hotKeys.ContainsKey(setting.Command))
						setting.HotKey = hotKeys[setting.Command];
				}
			}
		}
Beispiel #6
0
        /// <inheritdoc />
        public override void RemoveHotKeyAction(VirtualKeys key, Modifiers modifiers, EventHandler <HotKeyPressedEventArgs> handler)
        {
            // remove no repeat before adding to list to avoid getting different hash
            modifiers = (Modifiers)((uint)modifiers & 0xF);
            KeyModifierCombination combination = new KeyModifierCombination(key, modifiers);

            if (!HotKeys.ContainsKey(combination))
            {
                String error = $"No hotKey associated with {modifiers}+{key}";
                Logger.Warn(error);
                throw new HotKeyException(error);
            }

            HotKeys[combination].HotKeyPressedEvent -= handler;
        }
Beispiel #7
0
        /// <summary>
        /// Handles the KeyDown event of the FrmBase control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="KeyEventArgs" /> instance containing the event data.</param>
        protected void FrmBase_KeyDown(object sender, KeyEventArgs e)
        {
            if (HotKeyDown != null && HotKeys != null)
            {
                bool blnCtrl  = false;
                bool blnAlt   = false;
                bool blnShift = false;
                if (e.Control)
                {
                    blnCtrl = true;
                }
                if (e.Alt)
                {
                    blnAlt = true;
                }
                if (e.Shift)
                {
                    blnShift = true;
                }
                if (HotKeys.ContainsKey(e.KeyValue))
                {
                    string strKey = string.Empty;
                    if (blnCtrl)
                    {
                        strKey += "Ctrl+";
                    }
                    if (blnAlt)
                    {
                        strKey += "Alt+";
                    }
                    if (blnShift)
                    {
                        strKey += "Shift+";
                    }
                    strKey += HotKeys[e.KeyValue];

                    if (HotKeyDown(strKey))
                    {
                        e.Handled          = true;
                        e.SuppressKeyPress = true;
                    }
                }
            }
        }
Beispiel #8
0
        public static void UnregisterHotKey(CaptureMode mode)
        {
            if (Handle == IntPtr.Zero)
            {
                return;
            }
            if (!HotKeys.ContainsKey(mode))
            {
                return;
            }

            var hotKey = HotKeys[mode];

            if (hotKey == null)
            {
                return;
            }

            if (WindowNative.UnregisterHotKey(Handle, (int)mode))
            {
                hotKey.IsRegistered = false;
            }
        }
Beispiel #9
0
 public SettingPage(HotKeys hotKeys)
 {
     #region FileType Init
     FileRegisterLoad();
     #endregion
     InitializeComponent();
     #region 读取热键
     HotKeys = hotKeys;
     if (hotKeys != null)
     {
         foreach (var child in this.yy.Children)
         {
             if (child is HotKeySettingControl)
             {
                 HotKeySettingControl setting = child as HotKeySettingControl;
                 if (hotKeys.ContainsKey(setting.Command))
                 {
                     setting.HotKey = hotKeys[setting.Command];
                 }
             }
         }
     }
     #endregion
 }
Beispiel #10
0
 public bool ContainsKey(string key)
 {
     return(HotKeys.ContainsKey(key));
 }
Beispiel #11
0
 /// <inheritdoc />
 public override bool IsHotKeyAvailable(VirtualKeys virtualKey, Modifiers modifiers)
 {
     return(!HotKeys.ContainsKey(new KeyModifierCombination(virtualKey, modifiers)));
 }