PowerArgs.Cli.KeyboardInterceptionManager.TryIntercept C# (CSharp) Method

TryIntercept() public method

public TryIntercept ( ConsoleKeyInfo keyInfo ) : bool
keyInfo System.ConsoleKeyInfo
return bool
        public bool TryIntercept(ConsoleKeyInfo keyInfo)
        {
            bool alt = keyInfo.Modifiers.HasFlag(ConsoleModifiers.Alt);
            bool control = keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control);
            bool shift = keyInfo.Modifiers.HasFlag(ConsoleModifiers.Shift);
            bool noModifier = alt == false && shift == false && control == false;

            int handlerCount = 0;

            if(noModifier && nakedHandlers.ContainsKey(keyInfo.Key))
            {
                nakedHandlers[keyInfo.Key].Peek().Invoke(keyInfo);
                handlerCount++;
            }

            if(alt && altHandlers.ContainsKey(keyInfo.Key))
            {
                altHandlers[keyInfo.Key].Peek().Invoke(keyInfo);
                handlerCount++;
            }

            if (shift && shiftHandlers.ContainsKey(keyInfo.Key))
            {
                shiftHandlers[keyInfo.Key].Peek().Invoke(keyInfo);
                handlerCount++;
            }

            if (control && controlHandlers.ContainsKey(keyInfo.Key))
            {
                controlHandlers[keyInfo.Key].Peek().Invoke(keyInfo);
                handlerCount++;
            }

            return handlerCount > 0;
        }