Ejemplo n.º 1
0
        public static HotKey Register(Keys key, Modifiers modifiers, HotKeyCallBackHanlder callBack)
        {
            HotKey hotKey = new HotKey(key, modifiers, ++keyid);

            if (!WinApi.RegisterHotKey(handle, keyid, (uint)modifiers, (uint)key))
            {
                throw new Exception("Global Hotkey Registration Failed!");
            }

            keyMap[keyid] = callBack;

            return(hotKey);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers the system-wide hot key.
        /// </summary>
        /// <param name="hotKey">The hot key.</param>
        public void Register(HotKey hotKey)
        {
            // Check if specified hot key is already registered.
            if (_registered.ContainsKey(hotKey))
            {
                throw new ArgumentException("The specified hot key is already registered.");
            }

            // Register new hot key.
            var id = getFreeKeyId();

            if (!WinApi.RegisterHotKey(_windowHandleSource.Handle, id, hotKey.Key, hotKey.Modifiers))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Can't register the hot key.");
            }

            _registered.Add(hotKey, id);
        }