void LabelBox_KeyDown(GUIElement sender, KeyEventArgs e) { if (e.InterestingKeys.Contains<Keys>(Keys.LeftShift) || e.InterestingKeys.Contains<Keys>(Keys.RightShift)) caps = true; else caps = false; }
protected override void OnKeyPress(KeyEventArgs args) { if (args.Key == Keys.I) { args.Handled = true; Manager.NavigateToScreen(new InventoryScreen(Manager)); } }
protected override void OnKeyPress(KeyEventArgs args) { if (Manager.CanGoBack && args.Key == Keys.Escape) { args.Handled = true; Manager.NavigateBack(); } base.OnKeyPress(args); }
void LabelBox_KeyUp(GUIElement sender, KeyEventArgs e) { if (e.InterestingKeys.Contains(Keys.Back) && this.Text != String.Empty) Text = Text.Remove(this.Text.Length - 1); else if (e.InterestingKeys[0] == Keys.Space) this.Text += " "; else if (textKeys.Contains(e.InterestingKeys[0]) && this.Text.Length < MaxLength) this.Text += caps ? e.InterestingKeys[0].ToString() : e.InterestingKeys[0].ToString().ToLower(); else if (numKeys.Contains(e.InterestingKeys[0])) { string tempText = e.InterestingKeys[0].ToString(); this.Text += tempText.Remove(0, tempText.Length -1 ); } }
protected override void OnKeyPress(KeyEventArgs args) { base.OnKeyPress(args); if (Focused == TreeState.Active && (args.Key == Keys.Enter || args.Key == Keys.Space)) { EventArgs e = new EventArgs(); OnExecuted(e); if (Executed != null) Executed(this, e); args.Handled = true; } }
protected internal override void KeyDown(KeyEventArgs e) { lock (RenderRule) { if (RenderRule.Length != 0) { switch (e.KeyCode) { case Keys.Left: { RenderRule.TextCursor--; RenderRule.SelectedChar = null; break; } case Keys.Right: { RenderRule.TextCursor++; RenderRule.SelectedChar = null; break; } case Keys.Up: { RenderRule.CursorUp(); RenderRule.SelectedChar = null; break; } case Keys.Down: { RenderRule.CursorDown(); RenderRule.SelectedChar = null; break; } case Keys.Home: { RenderRule.CursorHome(); RenderRule.SelectedChar = null; break; } case Keys.End: { RenderRule.CursorEnd(); RenderRule.SelectedChar = null; break; } case Keys.PageUp: { RenderRule.TextCursor = 0; RenderRule.SelectedChar = null; break; } case Keys.PageDown: { RenderRule.TextCursor = RenderRule.Length; RenderRule.SelectedChar = null; break; } case Keys.Delete: { RenderRule.Delete(); RenderRule.BakeText(); RenderRule.SelectedChar = null; break; } } } } ResetTimer(); }
protected override void OnKeyPress(KeyEventArgs args) { if (Focused != TreeState.Active) return; if (Orientation == Orientation.Horizontal) { if (args.Key == Keys.Right && Value < Range) Value++; if (args.Key == Keys.Left && Value > 0) Value--; } else { if (args.Key == Keys.Up && Value < Range) Value++; if (args.Key == Keys.Down && Value > 0) Value--; } if (args.Key == Keys.D0) Value = 0; }
/// <summary> /// Вызывает делегат отпускания клавиши /// </summary> /// <param name="e"></param> protected internal virtual void OnKeyUp(KeyEventArgs e) { KeyUp?.Invoke(this, e); _isBlockedKeyBoard = true; }
/// <summary> /// Handling aller Eingaben, Mausbewegungen und Updaten aller Screens und Controls. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { if (Game.IsActive) { #region Mouse Interaction if (MouseEnabled) { MouseState mouse = Mouse.GetState(); // Mausposition anhand des Mouse Modes ermitteln Point mousePosition = mouse.Position; if (MouseMode == MouseMode.Captured) mousePosition = new Point( mousePosition.X - (GraphicsDevice.Viewport.Width / 2), mousePosition.Y - (GraphicsDevice.Viewport.Height / 2)); // Mouse Move if (mousePosition != lastMousePosition) { MouseEventArgs moveArgs = new MouseEventArgs() { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition, }; root.InternalMouseMove(moveArgs); if (!moveArgs.Handled && MouseMove != null) MouseMove(moveArgs); // Start Drag Handling if (mouse.LeftButton == ButtonState.Pressed && DraggingArgs == null) { DraggingArgs = new DragEventArgs() { GlobalPosition = mousePosition, LocalPosition = mousePosition, }; draggingId = null; root.InternalStartDrag(DraggingArgs); if (!DraggingArgs.Handled && StartDrag != null) StartDrag(DraggingArgs); } // Drop move if (mouse.LeftButton == ButtonState.Pressed && DraggingArgs != null && draggingId == null && DraggingArgs.Handled) { DragEventArgs args = new DragEventArgs() { GlobalPosition = mousePosition, LocalPosition = mousePosition, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalDropMove(args); if (!args.Handled && DropMove != null) DropMove(args); } } // Linke Maustaste if (mouse.LeftButton == ButtonState.Pressed) { if (!lastLeftMouseButtonPressed) { MouseEventArgs leftDownArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; // Linke Maustaste wurde neu gedrückt root.InternalLeftMouseDown(leftDownArgs); if (!leftDownArgs.Handled && LeftMouseDown != null) LeftMouseDown(leftDownArgs); } lastLeftMouseButtonPressed = true; } else { if (lastLeftMouseButtonPressed) { // Handle Drop if (DraggingArgs != null && DraggingArgs.Handled) { DragEventArgs args = new DragEventArgs() { GlobalPosition = mousePosition, LocalPosition = mousePosition, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalEndDrop(args); if (!args.Handled && EndDrop != null) EndDrop(args); } // Discard Dragging Infos DraggingArgs = null; draggingId = null; // Linke Maustaste wurde losgelassen MouseEventArgs leftClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalLeftMouseClick(leftClickArgs); if (!leftClickArgs.Handled && LeftMouseClick != null) LeftMouseClick(leftClickArgs); if (lastLeftClick.HasValue && gameTime.TotalGameTime - lastLeftClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Left Click MouseEventArgs leftDoubleClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalLeftMouseDoubleClick(leftDoubleClickArgs); if (!leftDoubleClickArgs.Handled && LeftMouseDoubleClick != null) LeftMouseDoubleClick(leftDoubleClickArgs); lastLeftClick = null; } else { lastLeftClick = gameTime.TotalGameTime; } // Mouse Up MouseEventArgs leftUpArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalLeftMouseUp(leftUpArgs); if (!leftUpArgs.Handled && LeftMouseUp != null) LeftMouseUp(leftUpArgs); } lastLeftMouseButtonPressed = false; } // Rechte Maustaste if (mouse.RightButton == ButtonState.Pressed) { if (!lastRightMouseButtonPressed) { // Rechte Maustaste neu gedrückt MouseEventArgs rightDownArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseDown(rightDownArgs); if (!rightDownArgs.Handled && RightMouseDown != null) RightMouseDown(rightDownArgs); } lastRightMouseButtonPressed = true; } else { if (lastRightMouseButtonPressed) { // Rechte Maustaste losgelassen MouseEventArgs rightClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseClick(rightClickArgs); if (!rightClickArgs.Handled && RightMouseClick != null) RightMouseClick(rightClickArgs); if (lastRightClick.HasValue && gameTime.TotalGameTime - lastRightClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Left Click MouseEventArgs rightDoubleClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseDoubleClick(rightDoubleClickArgs); if (!rightDoubleClickArgs.Handled && RightMouseDoubleClick != null) RightMouseDoubleClick(rightDoubleClickArgs); lastRightClick = null; } else { lastRightClick = gameTime.TotalGameTime; } MouseEventArgs rightUpArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseUp(rightUpArgs); if (!rightUpArgs.Handled && RightMouseUp != null) RightMouseUp(rightUpArgs); } lastRightMouseButtonPressed = false; } // Mousewheel if (lastMouseWheelValue != mouse.ScrollWheelValue) { int diff = (mouse.ScrollWheelValue - lastMouseWheelValue); MouseScrollEventArgs scrollArgs = new MouseScrollEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition, Steps = diff }; root.InternalMouseScroll(scrollArgs); if (!scrollArgs.Handled && MouseScroll != null) MouseScroll(scrollArgs); lastMouseWheelValue = mouse.ScrollWheelValue; } // Potentieller Positionsreset if (MouseMode == MouseMode.Free) { lastMousePosition = mouse.Position; } else if (mousePosition.X != 0 || mousePosition.Y != 0) { Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); } } #endregion #region Keyboard Interaction if (KeyboardEnabled) { KeyboardState keyboard = Keyboard.GetState(); bool shift = keyboard.IsKeyDown(Keys.LeftShift) | keyboard.IsKeyDown(Keys.RightShift); bool ctrl = keyboard.IsKeyDown(Keys.LeftControl) | keyboard.IsKeyDown(Keys.RightControl); bool alt = keyboard.IsKeyDown(Keys.LeftAlt) | keyboard.IsKeyDown(Keys.RightAlt); KeyEventArgs args; foreach (Keys key in Enum.GetValues(typeof(Keys))) { if (keyboard.IsKeyDown(key)) { if (!pressedKeys.ContainsKey(key)) { // Taste ist neu args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyDown(args); if (!args.Handled) { if (KeyDown != null) KeyDown(args); } args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyPress(args); pressedKeys.Add(key, gameTime.TotalGameTime.TotalMilliseconds + 500); // Spezialfall Tab-Taste (falls nicht verarbeitet wurde) if (key == Keys.Tab && !args.Handled) { if (shift) root.InternalTabbedBackward(); else root.InternalTabbedForward(); } } else { // Taste ist immernoch gedrückt if (pressedKeys[key] <= gameTime.TotalGameTime.TotalMilliseconds) { args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyPress(args); if (!args.Handled) { if (KeyPress != null) KeyPress(args); } pressedKeys[key] = gameTime.TotalGameTime.TotalMilliseconds + 50; } } } else { if (pressedKeys.ContainsKey(key)) { // Taste losgelassen args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyUp(args); pressedKeys.Remove(key); if (!args.Handled) { if (KeyUp != null) KeyUp(args); } } } } } #endregion #region Touchpanel Interaction if (TouchEnabled) { TouchCollection touchPoints = TouchPanel.GetState(); foreach (var touchPoint in touchPoints) { Point point = touchPoint.Position.ToPoint(); TouchEventArgs args = new TouchEventArgs() { TouchId = touchPoint.Id, GlobalPosition = point, LocalPosition = point }; switch (touchPoint.State) { case TouchLocationState.Pressed: root.InternalTouchDown(args); if (!args.Handled && TouchDown != null) TouchDown(args); break; case TouchLocationState.Moved: // Touch Move root.InternalTouchMove(args); if (!args.Handled && TouchMove != null) TouchMove(args); // Start Dragging if (DraggingArgs == null) { DraggingArgs = new DragEventArgs() { GlobalPosition = point, LocalPosition = point, }; draggingId = touchPoint.Id; root.InternalStartDrag(DraggingArgs); if (!DraggingArgs.Handled && StartDrag != null) StartDrag(DraggingArgs); } // Drop move if (DraggingArgs != null && draggingId == touchPoint.Id && DraggingArgs.Handled) { DragEventArgs moveArgs = new DragEventArgs() { GlobalPosition = point, LocalPosition = point, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalDropMove(moveArgs); if (!args.Handled && DropMove != null) DropMove(moveArgs); } break; case TouchLocationState.Released: // Handle Drop if (DraggingArgs != null && draggingId == touchPoint.Id && DraggingArgs.Handled) { DragEventArgs dropArgs = new DragEventArgs() { GlobalPosition = point, LocalPosition = point, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalEndDrop(dropArgs); if (!args.Handled && EndDrop != null) EndDrop(dropArgs); } // Discard Dragging Infos DraggingArgs = null; draggingId = null; // Linke Maustaste wurde losgelassen TouchEventArgs tapArgs = new TouchEventArgs { TouchId = touchPoint.Id, GlobalPosition = point, LocalPosition = point }; root.InternalTouchTap(tapArgs); if (!tapArgs.Handled && TouchTap != null) TouchTap(tapArgs); if (lastTouchTap.HasValue && gameTime.TotalGameTime - lastLeftClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Tap TouchEventArgs doubleTapArgs = new TouchEventArgs { TouchId = touchPoint.Id, GlobalPosition = point, LocalPosition = point }; root.InternalTouchDoubleTap(doubleTapArgs); if (!doubleTapArgs.Handled && TouchDoubleTap != null) TouchDoubleTap(doubleTapArgs); lastTouchTap = null; } else { lastTouchTap = gameTime.TotalGameTime; } root.InternalTouchUp(args); if (!args.Handled && TouchUp != null) TouchUp(args); break; } } } #endregion } #region Recalculate Sizes if (root.HasInvalidDimensions()) { Point available = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); Point required = root.GetExpectedSize(available); root.SetActualSize(available); } root.Update(gameTime); #endregion #region Form anpassen string screentitle = ActiveScreen != null ? ActiveScreen.Title : string.Empty; string windowtitle = TitlePrefix + (string.IsNullOrEmpty(screentitle) ? "" : " - " + screentitle); if (Game.Window != null && Game.Window.Title != windowtitle) Game.Window.Title = windowtitle; #endregion }
protected override void OnKeyPress(KeyEventArgs e) { base.OnKeyPress(e); if (e.Key == Keys.Right) { ItemIndex += 1; e.Handled = true; } if (e.Key == Keys.Left) { ItemIndex -= 1; e.Handled = true; } if (ItemIndex > Items.Count - 1) ItemIndex = 0; if (ItemIndex < 0) ItemIndex = Items.Count - 1; if (e.Key == Keys.Down && Items.Count > 0 && Items[ItemIndex].Items.Count > 0) { e.Handled = true; OnClick(new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero)); } if (e.Key == Keys.Escape) { e.Handled = true; ItemIndex = -1; } }
public void RecieveSpecialInput(Keys key, KeyEventArgs e) { if(Locked) return; }
protected override void OnKeyPress(KeyEventArgs e) { if (e.Key == Keys.Down) { e.Handled = true; itemIndex += sbVert.StepSize / 10; } else if (e.Key == Keys.Up) { e.Handled = true; itemIndex -= sbVert.StepSize / 10; } else if (e.Key == Keys.PageDown) { e.Handled = true; itemIndex += sbVert.PageSize / 10; } else if (e.Key == Keys.PageUp) { e.Handled = true; itemIndex -= sbVert.PageSize / 10; } else if (e.Key == Keys.Home) { e.Handled = true; itemIndex = 0; } else if (e.Key == Keys.End) { e.Handled = true; itemIndex = items.Count - 1; } if (itemIndex < 0) itemIndex = 0; else if (itemIndex >= Items.Count) itemIndex = Items.Count - 1; ItemIndex = itemIndex; base.OnKeyPress(e); }
void ListBox_KeyDown(GUIElement sender, KeyEventArgs e) { if (_pressedTime == -1 || _updateTime - _pressedTime > 100) { if (e.InterestingKeys.Contains<Keys>(Keys.Down)) { // Scroll Down if (SelectedItem + 1 > MaximimumElementsDisplayed) drawStart = SelectedItem + 1 - MaximimumElementsDisplayed; SelectedItem += (SelectedItem + 1 == Text.Count) ? 0 : 1; _pressedTime = _updateTime; } else if (e.InterestingKeys.Contains<Keys>(Keys.Up)) { // Scroll Up if (SelectedItem - 1 < drawStart && drawStart > 0) drawStart = SelectedItem - 1; SelectedItem -= (SelectedItem == 0) ? 0 : 1; _pressedTime = _updateTime; } } }
/// <summary> /// Raises the KeyReleased event. This is done automatically by a correctly configured component, /// but this is exposed publicly to allow programmatic key release events to occur. /// </summary> public void OnKeyReleased(object sender, KeyEventArgs args) { if (KeyReleased != null) { KeyReleased(sender, args); } }
protected override void OnKeyPress(KeyEventArgs args) { if (!IsActiveScreen) return; switch (args.Key) { case Keys.I: case Keys.Tab: args.Handled = true; Manager.NavigateToScreen(new InventoryScreen(Manager)); break; case Keys.F11: compass.Visible = !compass.Visible; toolbar.Visible = !toolbar.Visible; minimap.Visible = !minimap.Visible; crosshair.Visible = !crosshair.Visible; break; case Keys.F10: debug.Visible = !debug.Visible; break; case Keys.F12: if (Manager.MouseMode == MouseMode.Captured) Manager.FreeMouse(); else Manager.CaptureMouse(); break; case Keys.Escape: Manager.NavigateToScreen(new MainScreen(Manager)); break; case Keys.L: Manager.Player.ActorHost.AllBlocksDebug(); break; } }
protected override void OnKeyUp(KeyEventArgs args) { switch (args.Key) { case Keys.LeftShift: case Keys.RightShift: pressedShift = false; args.Handled = true; break; case Keys.W: pressedMoveUp = false; args.Handled = true; break; case Keys.A: pressedMoveLeft = false; args.Handled = true; break; case Keys.S: pressedMoveDown = false; args.Handled = true; break; case Keys.D: pressedMoveRight = false; args.Handled = true; break; case Keys.Up: pressedHeadUp = false; args.Handled = true; break; case Keys.Down: pressedHeadDown = false; args.Handled = true; break; case Keys.Left: pressedHeadLeft = false; args.Handled = true; break; case Keys.Right: pressedHeadRight = false; args.Handled = true; break; } base.OnKeyUp(args); }
protected override void OnKeyDown(KeyEventArgs args) { if (!IsActiveScreen) return; switch (args.Key) { case Keys.LeftShift: case Keys.RightShift: pressedShift = true; args.Handled = true; break; case Keys.W: pressedMoveUp = true; args.Handled = true; break; case Keys.A: pressedMoveLeft = true; args.Handled = true; break; case Keys.S: pressedMoveDown = true; args.Handled = true; break; case Keys.D: pressedMoveRight = true; args.Handled = true; break; case Keys.Up: pressedHeadUp = true; args.Handled = true; break; case Keys.Down: pressedHeadDown = true; args.Handled = true; break; case Keys.Left: pressedHeadLeft = true; args.Handled = true; break; case Keys.Right: pressedHeadRight = true; args.Handled = true; break; case Keys.E: Manager.Player.InteractInput = true; args.Handled = true; break; case Keys.Q: Manager.Player.ApplyInput = true; args.Handled = true; break; case Keys.Scroll: Manager.Player.FlymodeInput = true; args.Handled = true; break; case Keys.Space: Manager.Player.JumpInput = true; args.Handled = true; break; case Keys.D1: Manager.Player.SlotInput[pressedShift ? 10 : 0] = true; args.Handled = true; break; case Keys.D2: Manager.Player.SlotInput[pressedShift ? 11 : 1] = true; args.Handled = true; break; case Keys.D3: Manager.Player.SlotInput[pressedShift ? 12 : 2] = true; args.Handled = true; break; case Keys.D4: Manager.Player.SlotInput[pressedShift ? 13 : 3] = true; args.Handled = true; break; case Keys.D5: Manager.Player.SlotInput[pressedShift ? 14 : 4] = true; args.Handled = true; break; case Keys.D6: Manager.Player.SlotInput[pressedShift ? 15 : 5] = true; args.Handled = true; break; case Keys.D7: Manager.Player.SlotInput[pressedShift ? 16 : 6] = true; args.Handled = true; break; case Keys.D8: Manager.Player.SlotInput[pressedShift ? 17 : 7] = true; args.Handled = true; break; case Keys.D9: Manager.Player.SlotInput[pressedShift ? 18 : 8] = true; args.Handled = true; break; case Keys.D0: Manager.Player.SlotInput[pressedShift ? 19 : 9] = true; args.Handled = true; break; } base.OnKeyDown(args); }
public override void Update(GameTime gameTime) { #region Mouse Interaction if (Game.IsActive) { MouseState mouse = Mouse.GetState(); MouseEventArgs moveArgs = new MouseEventArgs() { GlobalPosition = mouse.Position, LocalPosition = mouse.Position, }; root.InternalMouseMove(moveArgs); // Linke Maustaste if (mouse.LeftButton == ButtonState.Pressed) { if (!lastLeftMouseButtonPressed) { // Linke Maustaste wurde neu gedrückt root.InternalLeftMouseDown(new MouseEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position }); } lastLeftMouseButtonPressed = true; } else { if (lastLeftMouseButtonPressed) { // Linke Maustaste wurde losgelassen root.InternalLeftMouseClick(new MouseEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position }); root.InternalLeftMouseUp(new MouseEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position }); } lastLeftMouseButtonPressed = false; } // Rechte Maustaste if (mouse.RightButton == ButtonState.Pressed) { if (!lastRightMouseButtonPressed) { // Rechte Maustaste neu gedrückt root.InternalRightMouseDown(new MouseEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position }); } lastRightMouseButtonPressed = true; } else { if (lastRightMouseButtonPressed) { // Rechte Maustaste losgelassen root.InternalRightMouseUp(new MouseEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position }); root.InternalRightMouseClick(new MouseEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position }); } lastRightMouseButtonPressed = false; } // Mousewheel if (lastMouseWheelValue != mouse.ScrollWheelValue) { int diff = (mouse.ScrollWheelValue - lastMouseWheelValue); root.InternalMouseScroll(new MouseScrollEventArgs { GlobalPosition = mouse.Position, LocalPosition = mouse.Position, Steps = diff }); lastMouseWheelValue = mouse.ScrollWheelValue; } // Potentieller Positionsreset if (moveArgs.ResetPosition) Mouse.SetPosition(lastMousePosition.X, lastMousePosition.Y); else lastMousePosition = mouse.Position; } #endregion #region Keyboard Interaction if (Game.IsActive) { KeyboardState keyboard = Keyboard.GetState(); bool shift = keyboard.IsKeyDown(Keys.LeftShift) | keyboard.IsKeyDown(Keys.RightShift); bool ctrl = keyboard.IsKeyDown(Keys.LeftControl) | keyboard.IsKeyDown(Keys.RightControl); bool alt = keyboard.IsKeyDown(Keys.LeftAlt) | keyboard.IsKeyDown(Keys.RightAlt); KeyEventArgs args; foreach (Keys key in Enum.GetValues(typeof(Keys))) { if (keyboard.IsKeyDown(key)) { if (!pressedKeys.ContainsKey(key)) { // Taste ist neu args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyDown(args); args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyPress(args); pressedKeys.Add(key, gameTime.TotalGameTime.TotalMilliseconds + 500); // Spezialfall Tab-Taste (falls nicht verarbeitet wurde) if (key == Keys.Tab && !args.Handled) { if (shift) root.InternalTabbedBackward(); else root.InternalTabbedForward(); } } else { // Taste ist immernoch gedrückt if (pressedKeys[key] <= gameTime.TotalGameTime.TotalMilliseconds) { args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyPress(args); pressedKeys[key] = gameTime.TotalGameTime.TotalMilliseconds + 50; } } } else { if (pressedKeys.ContainsKey(key)) { // Taste losgelassen args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyUp(args); pressedKeys.Remove(key); } } } } #endregion #region Recalculate Sizes if (root.HasInvalidDimensions()) { Point available = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); Point required = root.GetExpectedSize(available); root.SetActualSize(available); } root.Update(gameTime); #endregion #region Form anpassen string screentitle = ActiveScreen != null ? ActiveScreen.Title : string.Empty; string windowtitle = TitlePrefix + (string.IsNullOrEmpty(screentitle) ? "" : " - " + screentitle); if (Game.Window != null && Game.Window.Title != windowtitle) Game.Window.Title = windowtitle; #endregion }
protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Keys.Down) { e.Handled = true; btnDown_Click(this, new MouseEventArgs()); } base.OnKeyDown(e); }
private void Game1_KeyDown(object sender, KeyEventArgs e) { if (e.State.IsKeyDown(Keys.F1)) { FpsCounter.EnableFrameTime = !FpsCounter.EnableFrameTime; if (FpsCounter.EnableFrameTime) ShowMessage("Frame times are now visible.", new TimeSpan(0, 0, 1)); else ShowMessage("Frame times are now hidden.", new TimeSpan(0, 0, 1)); } if (e.State.IsKeyDown(Keys.F2)) { FpsCounter.Visible = !FpsCounter.Visible; if (FpsCounter.Visible) ShowMessage("Fps counter are now visible.", new TimeSpan(0, 0, 1)); else ShowMessage("Fps counter are now hidden.", new TimeSpan(0, 0, 1)); } }
private void TextBox_KeyUp(Control sender, KeyEventArgs e) { _isPress = false; }
public void RecieveInput(KeyEventArgs e) { if(Locked) return; }
private void TextBox_KeyDown(Control sender, KeyEventArgs e) { // ReSharper disable once SwitchStatementMissingSomeCases switch (e.KeyCode) { case Keys.Left: _positionCoretka = Math.Max(_positionCoretka - 1, 0); break; case Keys.Right: _positionCoretka = Math.Min(_positionCoretka + 1, Text.Length); break; case Keys.Home: _positionCoretka = 0; break; case Keys.End: _positionCoretka = Text.Length; break; case Keys.Delete: { if (Text.Length >= 1 && Text.Length - _positionCoretka > 0) Text = Text.Remove(_positionCoretka, 1); } break; case Keys.Back: { if (Text.Length >= 1) { if (_positionCoretka >= Text.Length) { Text = Text.Remove(Text.Length - 1); _positionCoretka--; } else if (_positionCoretka >= 1) { Text = Text.Remove(_positionCoretka - 1, 1); _positionCoretka--; } } } break; default: { if (e.KeyChar.Length == 0) break; if (MaxLenght >= 0) { if (Text.Length < MaxLenght) Text = Text.Insert(_positionCoretka++, e.KeyChar); } else Text = Text.Insert(_positionCoretka++, e.KeyChar); } break; } _ticked = 0f; }
void ListBox_KeyPressDown(GUIElement sender, KeyEventArgs e) { if (e.InterestingKeys.Contains<Keys>(Keys.Enter)) OnSelectionMade(); }
private void UpdateKeys(KeyboardState state, GameTime gameTime) { KeyEventArgs e = new KeyEventArgs(); e.Caps = (((ushort)NativeMethods.GetKeyState(0x14)) & 0xffff) != 0; foreach (Keys key in state.GetPressedKeys()) { if (key == Keys.LeftAlt || key == Keys.RightAlt) e.Alt = true; else if (key == Keys.LeftShift || key == Keys.RightShift) e.Shift = true; else if (key == Keys.LeftControl || key == Keys.RightControl) e.Control = true; } foreach (InputKey key in keys) { if (key.Key == Keys.LeftAlt || key.Key == Keys.RightAlt || key.Key == Keys.LeftShift || key.Key == Keys.RightShift || key.Key == Keys.LeftControl || key.Key == Keys.RightControl) { continue; } bool pressed = state.IsKeyDown(key.Key); double ms = gameTime.ElapsedGameTime.TotalMilliseconds; if (pressed) key.Countdown -= ms; if ((pressed) && (!key.Pressed)) { key.Pressed = true; e.Key = key.Key; if (KeyDown != null) KeyDown.Invoke(this, e); if (KeyPress != null) KeyPress.Invoke(this, e); } else if ((!pressed) && (key.Pressed)) { key.Pressed = false; key.Countdown = RepeatDelay; e.Key = key.Key; if (KeyUp != null) KeyUp.Invoke(this, e); } else if (key.Pressed && key.Countdown < 0) { key.Countdown = RepeatRate; e.Key = key.Key; if (KeyPress != null) KeyPress.Invoke(this, e); } } }
void ListBox_KeyUp(GUIElement sender, KeyEventArgs e) { _pressedTime = -1; }
/// <summary> /// Wird aufgerufen, wenn eine Taste gedrückt ist. /// </summary> /// <param name="args">Zusätzliche Daten zum Event.</param> protected override void OnKeyPress(KeyEventArgs args) { // Ignorieren, wenn kein Fokus if (Focused != TreeState.Active) return; // Linke Pfeiltaste if (args.Key == Keys.Left) { if (args.Ctrl) { int x = Math.Min(CursorPosition - 1, Text.Length - 1); while (x > 0 && Text[x] != ' ') x--; CursorPosition = x; } else { CursorPosition--; CursorPosition = Math.Max(CursorPosition, 0); } if (!args.Shift) SelectionStart = CursorPosition; args.Handled = true; } // Rechte Pfeiltaste if (args.Key == Keys.Right) { if (args.Ctrl) { int x = CursorPosition; while (x < Text.Length && Text[x] != ' ') x++; CursorPosition = Math.Min(x + 1, Text.Length); } else { CursorPosition++; CursorPosition = Math.Min(Text.Length, CursorPosition); } if (!args.Shift) SelectionStart = CursorPosition; args.Handled = true; } // Pos1-Taste if (args.Key == Keys.Home) { CursorPosition = 0; if (!args.Shift) SelectionStart = CursorPosition; args.Handled = true; } // Ende-Taste if (args.Key == Keys.End) { CursorPosition = Text.Length; if (!args.Shift) SelectionStart = CursorPosition; args.Handled = true; } // Backspace if (args.Key == Keys.Back) { if (SelectionStart != CursorPosition) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); Text = Text.Substring(0, from) + Text.Substring(to); CursorPosition = from; SelectionStart = from; } else if (CursorPosition > 0) { Text = Text.Substring(0, CursorPosition - 1) + Text.Substring(CursorPosition); CursorPosition--; SelectionStart--; } args.Handled = true; } // Entfernen if (args.Key == Keys.Delete) { if (SelectionStart != CursorPosition) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); Text = Text.Substring(0, from) + Text.Substring(to); CursorPosition = from; SelectionStart = from; } else if (CursorPosition < Text.Length) { Text = Text.Substring(0, CursorPosition) + Text.Substring(CursorPosition + 1); } args.Handled = true; } // Ctrl+A (Select all) if (args.Key == Keys.A && args.Ctrl) { // Alles markieren SelectionStart = 0; CursorPosition = Text.Length; args.Handled = true; } // Ctrl+C (Copy) if (args.Key == Keys.C && args.Ctrl) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); // Selektion kopieren if (from == to) SystemSpecific.ClearClipboard(); else SystemSpecific.SetClipboardText(Text.Substring(from, to - from)); args.Handled = true; } // Ctrl+X (Cut) if (args.Key == Keys.X && args.Ctrl) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); // Selektion ausschneiden if (from == to) SystemSpecific.ClearClipboard(); else SystemSpecific.SetClipboardText(Text.Substring(from, to - from)); CursorPosition = from; SelectionStart = from; Text = Text.Substring(0, from) + Text.Substring(to); args.Handled = true; } // Ctrl+V (Paste) if (args.Key == Keys.V && args.Ctrl) { // Selektierten Text löschen if (SelectionStart != CursorPosition) { int from = Math.Min(SelectionStart, CursorPosition); int to = Math.Max(SelectionStart, CursorPosition); Text = Text.Substring(0, from) + Text.Substring(to); CursorPosition = from; SelectionStart = from; } // Text einfügen und Cursor ans Ende setzen string paste = SystemSpecific.GetClipboardText(); Text = Text.Substring(0, CursorPosition) + paste + Text.Substring(CursorPosition); CursorPosition += paste.Length; SelectionStart = CursorPosition; args.Handled = true; } args.Handled = true; //Manche Keys weitergeben if (ignoreKeys.Contains(args.Key)) args.Handled = false; base.OnKeyPress(args); }
private void TextBox_KeyPresed(Control sender, KeyEventArgs e) { if (KeyInPresedLonger.IndexOfOnArray(e.KeyCode) == -1) return;// if Not Presed Longer _tickedPres += (float)e.GameTime.ElapsedGameTime.TotalSeconds; if (_tickedPres >= PresedCheckBegin) { _isPress = true; _tickedPres = 0f; return; } _ticked += (float)e.GameTime.ElapsedGameTime.TotalSeconds; if (_ticked < PresedCheck || !_isPress) return; TextBox_KeyDown(sender, e); _ticked = 0f; }
/// <summary> /// Констрктор для Базовой Инициализации /// </summary> /// <param name="window">Окно в котором будут Отображаться Контролы</param> internal static void ControlInicializer(IWindow window) { if (Graphics == null) Graphics = window.Graphics2D; if (Window == null) Window = window; _ticks = new TickEventArgs(Window, null); _mouseEventArgs = new MouseEventArgs(); _keyEventArgs = new KeyEventArgs(); }
protected override void OnKeyPress(KeyEventArgs args) { if (Focused == TreeState.Active) { if (Orientation == Orientation.Horizontal) { if (args.Key == Keys.Left) { SplitterPosition = ActualSplitterPosition - 5; args.Handled = true; } if (args.Key == Keys.Right) { SplitterPosition = ActualSplitterPosition + 5; args.Handled = true; } } if (Orientation == Orientation.Vertical) { if (args.Key == Keys.Up) { SplitterPosition = ActualSplitterPosition - 5; args.Handled = true; } if (args.Key == Keys.Down) { SplitterPosition = ActualSplitterPosition + 5; args.Handled = true; } } } base.OnKeyPress(args); }
private void QueryInput(KeyEventArgs e, char keyvalue) { KeyboardState state = Keyboard.GetState(); Keys[] keys = state.GetPressedKeys(); if (keys.Length > 0) switch (keys[0]) { case Keys.Delete: if (inputText.Length > 0 && cursor != inputText.Length) { inputText.Remove(cursor, 1); } return; case Keys.Back: if (inputText.Length > 0) { inputText.Remove(cursor - 1, 1); cursor--; } return; case Keys.Space: inputText.Append(" "); cursor++; return; case Keys.Left: if (cursor > 0) cursor--; return; case Keys.Right: if (cursor < inputText.Length) cursor++; return; } if ((int)keys[0] < 48 || (int)keys[0] > 90) return; if ((int)keys[0] >= 65) { string currentChar = keyvalue.ToString(); if (e.IsShiftDown) currentChar = currentChar.ToUpper(); inputText.Append(currentChar); } else inputText.Append(keyvalue); cursor++; }