Esempio n. 1
0
        public void RegisterHotkey()
        {
            if (HotKeyWindow == null)
            {
                HotKeyWindow = new HotKeyNativeWindow(this);
            }

            try
            {
                if (Key != Keys.None)
                {
                    HotKeyWindow.RegisterHotkey();
                }
                else
                {
                    if (HotKeyWindow.Handle != IntPtr.Zero)
                    {
                        HotKeyWindow.DestroyHandle();
                    }
                    HotKeyWindow = null;
                }
            }
            catch
            {
                if (HotKeyWindow.Handle != IntPtr.Zero)
                {
                    HotKeyWindow.DestroyHandle();
                }
                HotKeyWindow = null;
                throw;
            }

            IsRegistered = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Register a hotkey combination of one or more Modifers and a Key.
        /// </summary>
        /// <remarks>
        /// This method uses the values of the Modifiers and Key properties.  If
        /// Modifiers == Modifiers.None and Key = Keys.None then any current hotkey combination
        /// represented by this instance is deactivated.  Calling this method a subsequent time with
        /// a different combination will cause the current combination to be replaced and the new hotkey
        /// combination installed.  If the hotkey registration process fails (for example the hotkey combination
        /// is already registered) then a Win32Exception is thrown.
        /// </remarks>
        public void RegisterHotkey()
        {
            if (this.HotKeyWindow == null)
            {
                this.HotKeyWindow = new HotKeyNativeWindow(this);
            }

            try {
                if (Modifiers != Modifiers.None && Key != Keys.None)
                {
                    this.HotKeyWindow.RegisterHotkey();
                }
                else
                {
                    if (HotKeyWindow.Handle != IntPtr.Zero)
                    {
                        HotKeyWindow.DestroyHandle();
                    }
                    HotKeyWindow = null;
                }
            }
            catch {
                if (HotKeyWindow.Handle != IntPtr.Zero)
                {
                    HotKeyWindow.DestroyHandle();
                }
                this.HotKeyWindow = null;
                throw;
            }
        }
Esempio n. 3
0
        public bool RegisterHotkey()
        {
            if (HotKeyWindow == null)
            {
                HotKeyWindow = new HotKeyNativeWindow(this);
            }

            try
            {
                if (Key != Keys.None)
                {
                    HotKeyWindow.RegisterHotkey();
                }
                else
                {
                    if (HotKeyWindow.Handle != IntPtr.Zero)
                    {
                        HotKeyWindow.DestroyHandle();
                    }
                    HotKeyWindow = null;
                }

                IsRegistered = true;
            }
            catch
            {
                if (HotKeyWindow.Handle != IntPtr.Zero)
                {
                    HotKeyWindow.DestroyHandle();
                }
                HotKeyWindow = null;

                IsRegistered = false;
            }

            return(IsRegistered);
        }