Example #1
0
 /// Initializes a new instance of the <see cref="SystemHotKeyPressedEventArgs"/> class.
 /// <param name="hotKey">A <see cref="HotKey"/> instance that specifies which hot key was pressed.</param>
 public SystemHotKeyPressedEventArgs(HotKey hotKey)
 {
     _hotKey = hotKey;
 }
Example #2
0
 /// <summary>
 /// Unregisters the specific hot key.
 /// </summary>
 /// <param name="hotKey">The <see cref="HotKey"/> that needs to be unregistered.</param>
 /// <returns>A <see cref="bool"/> value that indicates whether the operation is successed.</returns>
 public bool Unregister(HotKey hotKey)
 {
     if (_hotKeys.ContainsKey(hotKey.Id))
     {
         Api.UnregisterHotKey(_listeningForm.Handle, hotKey.Id);
         _hotKeys.Remove(hotKey.Id);
         return true;
     }
     else
     {
         return false;
     }
 }
Example #3
0
        internal void InvokeSystemHotKeyPressed(HotKey hotKey)
        {
            SystemHotKeyPressedEventArgs e = new SystemHotKeyPressedEventArgs(hotKey);

            // Single click
            _lastPressedHotKey = hotKey;
            _lastPressedTime = DateTime.Now;

            OnSystemHotKeyPressed(e);
        }
Example #4
0
        /// Registers a new system hot key.
        /// <param name="hotKey">The <see cref="HotKey"/> that need to register.</param>
        /// <exception cref="InvalidOperationException">
        /// The same hot key or name already exists.
        /// </exception>
        public void Register(HotKey hotKey)
        {
            // Check for duplicate hot key name.
            foreach (HotKey existingHotKey in _hotKeys.Values)
            {
                if (existingHotKey.Name == hotKey.Name)
                {
                    throw new InvalidOperationException("The hot key with name of '" + hotKey.Name + "' has been already registered.");
                }

                if (existingHotKey.Modifiers == hotKey.Modifiers &&
                    existingHotKey.Key == hotKey.Key)
                {
                    throw new InvalidOperationException("The same hot key has been already registered.");
                }
            }

            // Register the hot key.
            hotKey.Id = nextId;
            _hotKeys.Add(nextId, hotKey);
            Api.RegisterHotKey(_listeningForm.Handle, nextId, (uint)(hotKey.Modifiers), hotKey.Key);

            // Increase the internal hot key id.
            nextId++;
        }