private void OnMenu(ConsoleMenuEventArgs e) { if (Menu != null) { Menu(this, e); } }
public void WriteEvents(IList <EventArgs> events, int nEvents) { // convert EventArgs to ConsoleInputEventInfo structures. var consoleEvents = new ConsoleInputEventInfo[nEvents]; for (int i = 0; i < nEvents; i++) { var e = events[i]; var 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; } 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); }
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; } } }
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; } } }