//****************************************************************************************************************************************************************************************************

        /// <summary>
        /// Callback function that is called whenever a key is pressed
        /// </summary>
        /// <param name="nCode">Hook code</param>
        /// <param name="wParam">Keyboard state</param>
        /// <param name="lParam">LowLevelKeyboardInputEvent data</param>
        /// <returns>IntPtr</returns>
        private IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            bool fEatKeyStroke = false;

            var wparamTyped = wParam.ToInt32();

            if (Enum.IsDefined(typeof(KeyboardState), wparamTyped))
            {
                object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent));
                LowLevelKeyboardInputEvent p = (LowLevelKeyboardInputEvent)o;

                var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wparamTyped, GetKeyName(p.VirtualCode));

                EventHandler <GlobalKeyboardHookEventArgs> handler = KeyboardPressed;
                handler?.Invoke(this, eventArguments);

                fEatKeyStroke = eventArguments.Handled;
            }

            return(fEatKeyStroke ? (IntPtr)1 : CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }
        public GlobalKeyboardHookEventArgs(LowLevelKeyboardInputEvent keyboardData, KeyboardState keyboardState, string keyName)
        {
            KeyboardData  = keyboardData;
            KeyboardState = keyboardState;
            KeyName       = keyName;

            if ((KeyboardData.VirtualCode >= VirtualKeyCodes.VK_0 && KeyboardData.VirtualCode <= VirtualKeyCodes.VK_9) || (KeyboardData.VirtualCode >= VirtualKeyCodes.VK_NUM0 && KeyboardData.VirtualCode <= VirtualKeyCodes.VK_NUM9))
            {
                KeyType = KeyTypes.Numeric;
            }
            else if (KeyboardData.VirtualCode >= VirtualKeyCodes.VK_A && KeyboardData.VirtualCode <= VirtualKeyCodes.VK_Z)
            {
                KeyType = KeyTypes.Letter;
            }
            else if (keyboardData.VirtualCode == VirtualKeyCodes.VK_NUMLOCK || keyboardData.VirtualCode == VirtualKeyCodes.VK_CAPITAL || keyboardData.VirtualCode == VirtualKeyCodes.VK_SCROLL)
            {
                KeyType = KeyTypes.Lock;
            }
            else
            {
                KeyType = KeyTypes.System;
            }
        }