示例#1
0
        /// <summary>
        /// Registers a Key Hook
        /// </summary>
        /// <param name="options">
        /// Options parameter containing the information required to register a key hook.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown in the attempt to register a key with an id that is already regiseted.
        /// </exception>
        public static void RegisterKey(KeyHookOptions options)
        {
            if (instance.KeyHooks.ContainsKey(options.Id))
            {
                throw new InvalidOperationException("A key hook has already been defined with an Id of " + options.Id);
            }

            var hook = new KeyHook(options.Handle, options.Id, options.Modifiers, options.Key);

            hook.HotKeyPressed = k => HookedKeyPress(instance, hook);

            if (options.Handler != null)
            {
                hook.HotKeyPressed = options.Handler;
            }

            instance.keyHooks[options.Id] = hook;

            if (instance.registeredDispose)
            {
                return;
            }

            instance.registeredDispose = true;
            RegisterDispose();
        }
示例#2
0
 /// <summary>
 /// Unregisters a Key Hook.
 /// </summary>
 /// <param name="keyHook">KeyHook to be unregistered.</param>
 public static void UnregisterKey(KeyHook keyHook)
 {
     UnregisterKey(keyHook.Id);
 }
示例#3
0
 private static void HookedKeyPress(NeatHook neatHook, KeyHook keyHook)
 {
     OnHookedKeyPress?.Invoke(neatHook, new KeyPressEventArgs {
         Key = keyHook.Key, Modifiers = keyHook.Modifiers
     });
 }