protected override void OnMouse(MOUSE_EVENT_RECORD m) { double rotSpeed = 3.0 * elapsed; if (m.dwMousePosition.X != lastMousePosX) { float deltaX = m.dwMousePosition.X - lastMousePosX; lastMousePosX = m.dwMousePosition.X; if (deltaX > 0) { double oldDirX = dirX; dirX = dirX * Math.Cos(-rotSpeed) - dirY * Math.Sin(-rotSpeed); dirY = oldDirX * Math.Sin(-rotSpeed) + dirY * Math.Cos(-rotSpeed); double oldPlaneX = planeX; planeX = planeX * Math.Cos(-rotSpeed) - planeY * Math.Sin(-rotSpeed); planeY = oldPlaneX * Math.Sin(-rotSpeed) + planeY * Math.Cos(-rotSpeed); } else { double oldDirX = dirX; dirX = dirX * Math.Cos(rotSpeed) - dirY * Math.Sin(rotSpeed); dirY = oldDirX * Math.Sin(rotSpeed) + dirY * Math.Cos(rotSpeed); double oldPlaneX = planeX; planeX = planeX * Math.Cos(rotSpeed) - planeY * Math.Sin(rotSpeed); planeY = oldPlaneX * Math.Sin(rotSpeed) + planeY * Math.Cos(rotSpeed); } } }
public ConsoleMouseEventArgs(MOUSE_EVENT_RECORD rec) { MousePosition = new Point(rec.MousePosition.X, rec.MousePosition.Y); ButtonState = rec.ButtonState; Scroll = rec.Scroll; ControlKeys = rec.ControlKeys; EventFlags = rec.EventFlags; }
private void OnMouseEvent(MOUSE_EVENT_RECORD MouseEvent) { Console.SetCursorPosition(0, 0); Console.WriteLine("Mouse event"); Console.WriteLine($" X ...............: {MouseEvent.dwMousePosition.X,4:0} "); Console.WriteLine($" Y ...............: {MouseEvent.dwMousePosition.Y,4:0} "); Console.WriteLine($" dwButtonState ...: 0x{MouseEvent.dwButtonState:X4} "); Console.WriteLine($" dwControlKeyState: 0x{MouseEvent.dwControlKeyState:X4} "); Console.WriteLine($" dwEventFlags ....: 0x{MouseEvent.dwEventFlags:X4} "); }
public Win32ConsoleMouseEvent(MOUSE_EVENT_RECORD mouseEvent) : base(mouseEvent.dwMousePosition.X, mouseEvent.dwMousePosition.Y, (TvConsoleMouseEventType)mouseEvent.dwEventFlags) { _mouseEvent = mouseEvent; var modifiers = _mouseEvent.dwControlKeyState.GetModifiers(); CtrlPressed = modifiers.ctrl; AltPressed = modifiers.alt; ShiftPressed = modifiers.shift; }
public void MouseEventArgs_ConstructorSetsCorrectValues() { MOUSE_EVENT_RECORD record = new MOUSE_EVENT_RECORD { ControlKeys = ControlKeyStates.LEFT_ALT_PRESSED, EventFlags = MouseEventFlags.DoubleClick, ButtonState = MouseButtonStates.FourthButtonPressed, MousePosition = new COORD(21, 42), Scroll = 123 }; var e = new ConsoleMouseEventArgs(record); var sut = new MouseEventArgs(e); sut.ControlKeys.Should().Be(record.ControlKeys); sut.ButtonState.Should().Be(record.ButtonState); sut.Kind.Should().Be(record.EventFlags); sut.Position.Should().Be(e.MousePosition); sut.Scroll.Should().Be(record.Scroll); }
private static void ConsoleListener_MouseEvent(MOUSE_EVENT_RECORD r) { if (!updatingHeader && r.dwButtonState == 1 && (r.dwMousePosition.X != previousMousePositionX || r.dwMousePosition.Y != previousMousePositionY)) { var gameObjectFound = gameBuffer.FirstOrDefault(cc => cc.X == r.dwMousePosition.X && cc.Y == r.dwMousePosition.Y); if (gameObjectFound != null) { gameObjectFound.Clear(); gameBuffer.Remove(gameObjectFound); if (gameObjectFound.Value.Text[0] == characterBrushes[4]) { score += 1; } else if (gameObjectFound.Value.Text[0] == characterBrushes[5]) { lives += 1; } else if (gameObjectFound.Value.Text[0] == characterBrushes[6] || gameObjectFound.Value.Text[0] == characterBrushes[7] || gameObjectFound.Value.Text[0] == characterBrushes[8]) { lives -= 1; Console.Beep(); if (lives == 0) { LoadScreen("End.txt"); gameState = GameState.GameOver; } } } var newCommand = new ConsoleCommand(r.dwMousePosition.X, r.dwMousePosition.Y, AnsiString.Create(activeBrush.ToString()).Colored(activeColor, ConsoleColor.Black)); newCommand.Execute(); commandBuffer.Add(newCommand); previousMousePositionX = r.dwMousePosition.X; previousMousePositionY = r.dwMousePosition.Y; } }
protected virtual void OnMouse(MOUSE_EVENT_RECORD m) { }
public void ParseInputEvent(INPUT_RECORD inputRecord, Control rootElement) { if (inputRecord.EventType == EventType.MOUSE_EVENT) { MOUSE_EVENT_RECORD mouseEvent = inputRecord.MouseEvent; if (mouseEvent.dwEventFlags != MouseEventFlags.PRESSED_OR_RELEASED && mouseEvent.dwEventFlags != MouseEventFlags.MOUSE_MOVED && mouseEvent.dwEventFlags != MouseEventFlags.DOUBLE_CLICK && mouseEvent.dwEventFlags != MouseEventFlags.MOUSE_WHEELED && mouseEvent.dwEventFlags != MouseEventFlags.MOUSE_HWHEELED) { // throw new InvalidOperationException("Flags combination in mouse event was not expected."); } Point rawPosition; if (mouseEvent.dwEventFlags == MouseEventFlags.MOUSE_MOVED || mouseEvent.dwEventFlags == MouseEventFlags.PRESSED_OR_RELEASED) { rawPosition = new Point(mouseEvent.dwMousePosition.X, mouseEvent.dwMousePosition.Y); lastMousePosition = rawPosition; } else { // При событии MOUSE_WHEELED в Windows некорректно устанавливается mouseEvent.dwMousePosition // Поэтому для определения элемента, над которым производится прокручивание колёсика, мы // вынуждены сохранять координаты, полученные при предыдущем событии мыши rawPosition = lastMousePosition; } Control topMost = VisualTreeHelper.FindTopControlUnderMouse(rootElement, Control.TranslatePoint(null, rawPosition, rootElement)); // если мышь захвачена контролом, то события перемещения мыши доставляются только ему, // события, связанные с нажатием мыши - тоже доставляются только ему, вместо того // контрола, над которым событие было зарегистрировано. Такой механизм необходим, // например, для корректной обработки перемещений окон (вверх или в стороны) Control source = (inputCaptureStack.Count != 0) ? inputCaptureStack.Peek() : topMost; // No sense to further process event with no source control if (source == null) { return; } if (mouseEvent.dwEventFlags == MouseEventFlags.MOUSE_MOVED) { MouseButtonState leftMouseButtonState = getLeftButtonState(mouseEvent.dwButtonState); MouseButtonState middleMouseButtonState = getMiddleButtonState(mouseEvent.dwButtonState); MouseButtonState rightMouseButtonState = getRightButtonState(mouseEvent.dwButtonState); // MouseEventArgs mouseEventArgs = new MouseEventArgs(source, Control.PreviewMouseMoveEvent, rawPosition, leftMouseButtonState, middleMouseButtonState, rightMouseButtonState ); eventsQueue.Enqueue(mouseEventArgs); // lastLeftMouseButtonState = leftMouseButtonState; lastMiddleMouseButtonState = middleMouseButtonState; lastRightMouseButtonState = rightMouseButtonState; // detect mouse enter / mouse leave events // path to source from root element down List <Control> mouseOverStack = new List <Control>(); Control current = topMost; while (null != current) { mouseOverStack.Insert(0, current); current = current.Parent; } int index; for (index = 0; index < Math.Min(mouseOverStack.Count, prevMouseOverStack.Count); index++) { if (mouseOverStack[index] != prevMouseOverStack[index]) { break; } } for (int i = prevMouseOverStack.Count - 1; i >= index; i--) { Control control = prevMouseOverStack[i]; MouseEventArgs args = new MouseEventArgs(control, Control.MouseLeaveEvent, rawPosition, leftMouseButtonState, middleMouseButtonState, rightMouseButtonState ); eventsQueue.Enqueue(args); } for (int i = index; i < mouseOverStack.Count; i++) { // enqueue MouseEnter event Control control = mouseOverStack[i]; MouseEventArgs args = new MouseEventArgs(control, Control.MouseEnterEvent, rawPosition, leftMouseButtonState, middleMouseButtonState, rightMouseButtonState ); eventsQueue.Enqueue(args); } prevMouseOverStack.Clear(); prevMouseOverStack.AddRange(mouseOverStack); } if (mouseEvent.dwEventFlags == MouseEventFlags.PRESSED_OR_RELEASED) { // MouseButtonState leftMouseButtonState = getLeftButtonState(mouseEvent.dwButtonState); MouseButtonState middleMouseButtonState = getMiddleButtonState(mouseEvent.dwButtonState); MouseButtonState rightMouseButtonState = getRightButtonState(mouseEvent.dwButtonState); // MouseButtonEventArgs eventArgs = null; if (leftMouseButtonState != lastLeftMouseButtonState) { eventArgs = new MouseButtonEventArgs(source, leftMouseButtonState == MouseButtonState.Pressed ? Control.PreviewMouseDownEvent : Control.PreviewMouseUpEvent, rawPosition, leftMouseButtonState, lastMiddleMouseButtonState, lastRightMouseButtonState, MouseButton.Left ); } if (middleMouseButtonState != lastMiddleMouseButtonState) { eventArgs = new MouseButtonEventArgs(source, middleMouseButtonState == MouseButtonState.Pressed ? Control.PreviewMouseDownEvent : Control.PreviewMouseUpEvent, rawPosition, lastLeftMouseButtonState, middleMouseButtonState, lastRightMouseButtonState, MouseButton.Middle ); } if (rightMouseButtonState != lastRightMouseButtonState) { eventArgs = new MouseButtonEventArgs(source, rightMouseButtonState == MouseButtonState.Pressed ? Control.PreviewMouseDownEvent : Control.PreviewMouseUpEvent, rawPosition, lastLeftMouseButtonState, lastMiddleMouseButtonState, rightMouseButtonState, MouseButton.Right ); } if (eventArgs != null) { eventsQueue.Enqueue(eventArgs); } // lastLeftMouseButtonState = leftMouseButtonState; lastMiddleMouseButtonState = middleMouseButtonState; lastRightMouseButtonState = rightMouseButtonState; if (leftMouseButtonState == MouseButtonState.Pressed) { if (eventArgs != null && !autoRepeatTimerRunning) { startAutoRepeatTimer(eventArgs); } } else { if (eventArgs != null && autoRepeatTimerRunning) { stopAutoRepeatTimer( ); } } } if (mouseEvent.dwEventFlags == MouseEventFlags.MOUSE_WHEELED) { MouseWheelEventArgs args = new MouseWheelEventArgs( topMost, Control.PreviewMouseWheelEvent, rawPosition, lastLeftMouseButtonState, lastMiddleMouseButtonState, lastRightMouseButtonState, mouseEvent.dwButtonState > 0 ? 1 : -1 ); eventsQueue.Enqueue(args); } } if (inputRecord.EventType == EventType.KEY_EVENT) { KEY_EVENT_RECORD keyEvent = inputRecord.KeyEvent; KeyEventArgs eventArgs = new KeyEventArgs( ConsoleApplication.Instance.FocusManager.FocusedElement, keyEvent.bKeyDown ? Control.PreviewKeyDownEvent : Control.PreviewKeyUpEvent); eventArgs.UnicodeChar = keyEvent.UnicodeChar; eventArgs.bKeyDown = keyEvent.bKeyDown; eventArgs.dwControlKeyState = keyEvent.dwControlKeyState; eventArgs.wRepeatCount = keyEvent.wRepeatCount; eventArgs.wVirtualKeyCode = keyEvent.wVirtualKeyCode; eventArgs.wVirtualScanCode = keyEvent.wVirtualScanCode; eventsQueue.Enqueue(eventArgs); } }
internal MouseMessage(MOUSE_EVENT_RECORD record) { _record = record; }