示例#1
0
 private void OnBufferSizeChange(ConsoleWindowBufferSizeEventArgs e)
 {
     if (BufferSizeChange != null)
     {
         BufferSizeChange(this, e);
     }
 }
示例#2
0
        public void WriteEvents(EventArgs[] events, int nEvents)
        {
            // convert EventArgs to ConsoleInputEventInfo structures.
            ConsoleInputEventInfo[] consoleEvents = new ConsoleInputEventInfo[nEvents];
            for (int i = 0; i < nEvents; i++)
            {
                EventArgs             e  = events[i];
                ConsoleInputEventInfo ce = new ConsoleInputEventInfo();

                if (e is ConsoleKeyEventArgs)
                {
                    ConsoleKeyEventArgs eKey = e as ConsoleKeyEventArgs;
                    ce.EventType                = ConsoleInputEventType.KeyEvent;
                    ce.KeyEvent.UnicodeChar     = eKey.KeyChar;
                    ce.KeyEvent.ControlKeyState = eKey.ControlKeyState;
                    ce.KeyEvent.KeyDown         = eKey.KeyDown;
                    ce.KeyEvent.RepeatCount     = (short)eKey.RepeatCount;
                    ce.KeyEvent.VirtualKeyCode  = eKey.Key;
                    ce.KeyEvent.VirtualScanCode = (short)eKey.VirtualScanCode;
                }
                else if (e is ConsoleMouseEventArgs)
                {
                    ConsoleMouseEventArgs eMouse = e as ConsoleMouseEventArgs;
                    ce.EventType = ConsoleInputEventType.MouseEvent;
                    ce.MouseEvent.ButtonState     = eMouse.ButtonState;
                    ce.MouseEvent.ControlKeyState = eMouse.KeyState;
                    ce.MouseEvent.EventFlags      = eMouse.EventFlags;
                    ce.MouseEvent.MousePosition   = new Coord((short)eMouse.X, (short)eMouse.Y);
                }
                else if (e is ConsoleFocusEventArgs)
                {
                    ConsoleFocusEventArgs eFocus = e as ConsoleFocusEventArgs;
                    ce.EventType           = ConsoleInputEventType.FocusEvent;
                    ce.FocusEvent.SetFocus = eFocus.SetFocus;
                }
                else if (e is ConsoleMenuEventArgs)
                {
                    ConsoleMenuEventArgs eMenu = e as ConsoleMenuEventArgs;
                    ce.EventType           = ConsoleInputEventType.MenuEvent;
                    ce.MenuEvent.CommandId = eMenu.CommandId;
                }
                else if (e is ConsoleWindowBufferSizeEventArgs)
                {
                    ConsoleWindowBufferSizeEventArgs eWindow = e as ConsoleWindowBufferSizeEventArgs;
                    ce.EventType = ConsoleInputEventType.WindowBufferSizeEvent;
                    ce.WindowBufferSizeEvent.Size = new Coord((short)eWindow.X, (short)eWindow.Y);
                }
                else
                {
                    throw new ApplicationException("Unknown event type.");
                }
                consoleEvents[i] = ce;
            }
            WriteEvents(consoleEvents, consoleEvents.Length);
        }
示例#3
0
        public void ProcessEvents()
        {
            int nEvents = this.NumInputEvents;

            if (nEvents == 0)
            {
                return;
            }
            ConsoleInputEventInfo[] events = ReadEvents(nEvents);
            for (int i = 0; i < events.Length; i++)
            {
                switch (events[i].EventType)
                {
                case ConsoleInputEventType.KeyEvent:
                    ConsoleKeyEventArgs eKey = new ConsoleKeyEventArgs(ref events[i].KeyEvent);
                    if (eKey.KeyDown)
                    {
                        OnKeyDown(eKey);
                    }
                    else
                    {
                        OnKeyUp(eKey);
                    }
                    break;

                case ConsoleInputEventType.MouseEvent:
                    ConsoleMouseEventArgs eMouse = new ConsoleMouseEventArgs(ref events[i].MouseEvent);
                    if ((((int)eMouse.EventFlags) & 0xfffff) == 0)
                    {
                        eMouse.EventFlags = ConsoleMouseEventType.MouseButton;
                        OnMouseButton(eMouse);
                    }
                    else if ((eMouse.EventFlags & ConsoleMouseEventType.DoubleClick) != 0)
                    {
                        eMouse.EventFlags = ConsoleMouseEventType.DoubleClick;
                        OnMouseDoubleClick(eMouse);
                    }
                    else if ((eMouse.EventFlags & (ConsoleMouseEventType.MouseHWheeled | ConsoleMouseEventType.MouseWheeled)) != 0)
                    {
                        eMouse.EventFlags = eMouse.EventFlags & (ConsoleMouseEventType.MouseHWheeled | ConsoleMouseEventType.MouseWheeled);
                        OnMouseScroll(eMouse);
                    }
                    else if ((eMouse.EventFlags & ConsoleMouseEventType.MouseMoved) != 0)
                    {
                        eMouse.EventFlags = ConsoleMouseEventType.MouseMoved;
                        OnMouseMove(eMouse);
                    }
                    break;

                case ConsoleInputEventType.WindowBufferSizeEvent:
                    ConsoleWindowBufferSizeEventArgs eBuff = new ConsoleWindowBufferSizeEventArgs(ref events[i].WindowBufferSizeEvent);
                    OnBufferSizeChange(eBuff);
                    break;

                case ConsoleInputEventType.FocusEvent:
                    ConsoleFocusEventArgs eFocus = new ConsoleFocusEventArgs(events[i].FocusEvent.SetFocus);
                    OnFocus(eFocus);
                    break;

                case ConsoleInputEventType.MenuEvent:
                    ConsoleMenuEventArgs eMenu = new ConsoleMenuEventArgs(events[i].MenuEvent.CommandId);
                    OnMenu(eMenu);
                    break;
                }
            }
        }
示例#4
0
 private void OnBufferSizeChange(ConsoleWindowBufferSizeEventArgs e)
 {
     if (BufferSizeChange != null)
     {
         BufferSizeChange(this, e);
     }
 }
示例#5
0
        public void ProcessEvents()
        {
            int nEvents = this.NumInputEvents;
            if (nEvents == 0)
                return;
            ConsoleInputEventInfo[] events = ReadEvents(nEvents);
            for (int i = 0; i < events.Length; i++)
            {
                switch (events[i].EventType)
                {
                    case ConsoleInputEventType.KeyEvent :
                        ConsoleKeyEventArgs eKey = new ConsoleKeyEventArgs(ref events[i].KeyEvent);
                        if (eKey.KeyDown)
                            OnKeyDown(eKey);
                        else
                            OnKeyUp(eKey);
                        break;

                    case ConsoleInputEventType.MouseEvent :
                        ConsoleMouseEventArgs eMouse = new ConsoleMouseEventArgs(ref events[i].MouseEvent);
                        if ((((int)eMouse.EventFlags) & 0xfffff) == 0)
                        {
                            eMouse.EventFlags = ConsoleMouseEventType.MouseButton;
                            OnMouseButton(eMouse);
                        }
                        else if ((eMouse.EventFlags & ConsoleMouseEventType.DoubleClick) != 0)
                        {
                            eMouse.EventFlags = ConsoleMouseEventType.DoubleClick;
                            OnMouseDoubleClick(eMouse);
                        }
                        else if ((eMouse.EventFlags & (ConsoleMouseEventType.MouseHWheeled | ConsoleMouseEventType.MouseWheeled)) != 0)
                        {
                            eMouse.EventFlags = eMouse.EventFlags & (ConsoleMouseEventType.MouseHWheeled | ConsoleMouseEventType.MouseWheeled);
                            OnMouseScroll(eMouse);
                        }
                        else if ((eMouse.EventFlags & ConsoleMouseEventType.MouseMoved) != 0)
                        {
                            eMouse.EventFlags = ConsoleMouseEventType.MouseMoved;
                            OnMouseMove(eMouse);
                        }
                        break;

                    case ConsoleInputEventType.WindowBufferSizeEvent :
                        ConsoleWindowBufferSizeEventArgs eBuff = new ConsoleWindowBufferSizeEventArgs(ref events[i].WindowBufferSizeEvent);
                        OnBufferSizeChange(eBuff);
                        break;

                    case ConsoleInputEventType.FocusEvent :
                        ConsoleFocusEventArgs eFocus = new ConsoleFocusEventArgs(events[i].FocusEvent.SetFocus);
                        OnFocus(eFocus);
                        break;

                    case ConsoleInputEventType.MenuEvent :
                        ConsoleMenuEventArgs eMenu = new ConsoleMenuEventArgs(events[i].MenuEvent.CommandId);
                        OnMenu(eMenu);
                        break;
                }
            }
        }