コード例 #1
0
ファイル: GlobalKeyHook.cs プロジェクト: scslmd/GlobalHooks
        /// <summary>
        /// This method will call the OnKeyUp event exposed from the library and pass on the information about the key that was pressed.
        /// </summary>
        /// <param name="e">Argument passed by the KeyboardPressed event found in the internal GlobalKeyboardHook class.</param>
        /// <returns>Returns true if the event was handled and false if not.</returns>
        bool KeyUp(GlobalKeyboardHookEventArgs e)
        {
            GlobalKeyEventArgs globalKeyEventArgs = new GlobalKeyEventArgs(e, alt, ctrl, shift);

            EventHandler <GlobalKeyEventArgs> handler = OnKeyUp;

            if (handler == null)
            {
                return(false);
            }
            handler(this, globalKeyEventArgs);
            return(globalKeyEventArgs.Handled);
        }
コード例 #2
0
ファイル: GlobalKeyHook.cs プロジェクト: scslmd/GlobalHooks
        /// <summary>
        /// This method will call the OnKeyPressed event exposed from the library and pass on the information about the key that was pressed.
        /// </summary>
        /// <param name="e">Argument passed by the KeyboardPressed event found in the internal GlobalKeyboardHook class.</param>
        /// <returns>Returns true if the event was handled and false if not.</returns>
        bool KeyPressed(GlobalKeyboardHookEventArgs e)
        {
            GlobalKeyEventArgs globalKeyEventArgs = new GlobalKeyEventArgs(e, alt, ctrl, shift); //Store the information passed to this method by the _OnKeyPressed method. This variable will be passed to the methods subscribed to the OnKeyPressed event.

            EventHandler <GlobalKeyEventArgs> handler = OnKeyPressed;

            if (handler == null) //If there's nothing subscribed to the OnKeyPressed event, we exit from the method.
            {
                return(false);
            }
            handler(this, globalKeyEventArgs);  //Call the OnKeyPressed event and pass on the globalKeyEventArgs as an argument
            return(globalKeyEventArgs.Handled); //Now, we return the bool value of the handled variable back to the _OnKeyPressed method.
        }