Exemplo n.º 1
0
        private ConsoleKeyInfo ToConsoleKeyInfo(WindowsConsole.KeyEventRecord keyEvent)
        {
            var state = keyEvent.dwControlKeyState;

            bool shift   = (state & WindowsConsole.ControlKeyState.ShiftPressed) != 0;
            bool alt     = (state & (WindowsConsole.ControlKeyState.LeftAltPressed | WindowsConsole.ControlKeyState.RightAltPressed)) != 0;
            bool control = (state & (WindowsConsole.ControlKeyState.LeftControlPressed | WindowsConsole.ControlKeyState.RightControlPressed)) != 0;

            return(new ConsoleKeyInfo(keyEvent.UnicodeChar, (ConsoleKey)keyEvent.wVirtualKeyCode, shift, alt, control));
        }
Exemplo n.º 2
0
        public ConsoleKeyInfoEx ToConsoleKeyInfoEx(WindowsConsole.KeyEventRecord keyEvent)
        {
            var state = keyEvent.dwControlKeyState;

            bool shift    = (state & WindowsConsole.ControlKeyState.ShiftPressed) != 0;
            bool alt      = (state & (WindowsConsole.ControlKeyState.LeftAltPressed | WindowsConsole.ControlKeyState.RightAltPressed)) != 0;
            bool control  = (state & (WindowsConsole.ControlKeyState.LeftControlPressed | WindowsConsole.ControlKeyState.RightControlPressed)) != 0;
            bool capslock = (state & (WindowsConsole.ControlKeyState.CapslockOn)) != 0;
            bool numlock  = (state & (WindowsConsole.ControlKeyState.NumlockOn)) != 0;

            var ConsoleKeyInfo = new ConsoleKeyInfo(keyEvent.UnicodeChar, (ConsoleKey)keyEvent.wVirtualKeyCode, shift, alt, control);

            return(new ConsoleKeyInfoEx(ConsoleKeyInfo, capslock, numlock));
        }
Exemplo n.º 3
0
        public ConsoleKeyInfoEx ToConsoleKeyInfoEx(WindowsConsole.KeyEventRecord keyEvent)
        {
            var state = keyEvent.dwControlKeyState;

            bool shift      = (state & WindowsConsole.ControlKeyState.ShiftPressed) != 0;
            bool alt        = (state & (WindowsConsole.ControlKeyState.LeftAltPressed | WindowsConsole.ControlKeyState.RightAltPressed)) != 0;
            bool control    = (state & (WindowsConsole.ControlKeyState.LeftControlPressed | WindowsConsole.ControlKeyState.RightControlPressed)) != 0;
            bool capslock   = (state & (WindowsConsole.ControlKeyState.CapslockOn)) != 0;
            bool numlock    = (state & (WindowsConsole.ControlKeyState.NumlockOn)) != 0;
            bool scrolllock = (state & (WindowsConsole.ControlKeyState.ScrolllockOn)) != 0;

            if (keyModifiers == null)
            {
                keyModifiers = new KeyModifiers();
            }
            if (shift)
            {
                keyModifiers.Shift = shift;
            }
            if (alt)
            {
                keyModifiers.Alt = alt;
            }
            if (control)
            {
                keyModifiers.Ctrl = control;
            }
            if (capslock)
            {
                keyModifiers.Capslock = capslock;
            }
            if (numlock)
            {
                keyModifiers.Numlock = numlock;
            }
            if (scrolllock)
            {
                keyModifiers.Scrolllock = scrolllock;
            }

            var ConsoleKeyInfo = new ConsoleKeyInfo(keyEvent.UnicodeChar, (ConsoleKey)keyEvent.wVirtualKeyCode, shift, alt, control);

            return(new ConsoleKeyInfoEx(ConsoleKeyInfo, capslock, numlock));
        }