private bool IsKeyPressed(GameKey gameKey) { if (!_gameWindow.Focused) { return(false); } switch (gameKey) { case GameKey.Jump: return(_keyboardState.IsKeyDown(OpenTK.Input.Key.Space)); case GameKey.Forwards: return(_keyboardState.IsKeyDown(OpenTK.Input.Key.W)); case GameKey.Left: return(_keyboardState.IsKeyDown(OpenTK.Input.Key.A)); case GameKey.Backwards: return(_keyboardState.IsKeyDown(OpenTK.Input.Key.S)); case GameKey.Right: return(_keyboardState.IsKeyDown(OpenTK.Input.Key.D)); case GameKey.Primary: return(_mouseState.LeftButton == ButtonState.Pressed); case GameKey.Secondary: return(_mouseState.RightButton == ButtonState.Pressed); default: return(false); } }
private static void InputTick(object sender, EventArgs e) { float speed = 0.01f * (float)ControlsWindow.camSpeed; OpenTK.Input.MouseState mouseState = OpenTK.Input.Mouse.GetState(); OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); if (keyboardState.IsKeyDown(Key.Up)) { dragY = dragY + speed; } if (keyboardState.IsKeyDown(Key.Down)) { dragY = dragY - speed; } if (keyboardState.IsKeyDown(Key.Left)) { angle = angle + speed; } if (keyboardState.IsKeyDown(Key.Right)) { angle = angle - speed; } if (keyboardState.IsKeyDown(Key.Z)) { dragZ = dragZ - speed; } if (keyboardState.IsKeyDown(Key.X)) { dragZ = dragZ + speed; } if (keyboardState.IsKeyDown(Key.Q)) { angle = angle + 0.5f; } if (keyboardState.IsKeyDown(Key.E)) { angle = angle - 0.5f; } //if (mouseInRender) //{ //dragZ = (mouseState.WheelPrecise / speed) - (7.5f); //Startzoom is at -7.5f //} }
protected override void OnUpdateFrame(OpenTK.FrameEventArgs e) { OpenTK.Input.KeyboardState input = OpenTK.Input.Keyboard.GetState(); if (input.IsKeyDown(OpenTK.Input.Key.Escape)) { Exit(); } base.OnUpdateFrame(e); }
public TkKeyboardState(OpenTK.Input.KeyboardState tkState) { if (tkState.IsAnyKeyDown) { foreach (var key in all_keys) { if (tkState.IsKeyDown(key)) { Keys.SetPressed(key, true); } } } }
public override void UpdateInput(bool isActive) { OpenTK.Input.KeyboardState state = OpenTK.Input.Keyboard.GetState(); PressedKeys.Clear(); if (state.IsAnyKeyDown) { foreach (Key k in Enum.GetValues(typeof(Key))) { if (state.IsKeyDown(k)) { PressedKeys.Add(k); } } } }
public bool UpdateHotkeys(Inp.KeyboardState newKeyboardState, Inp.KeyboardState oldKeyboardState) { if (Hotkey != Inp.Key.Unknown && (newKeyboardState.IsKeyDown(Inp.Key.LControl) || newKeyboardState.IsKeyDown(Inp.Key.RControl)) && newKeyboardState.IsKeyDown(Hotkey) && oldKeyboardState.IsKeyUp(Hotkey)) { if (BoundBool != null) { BoundBool.Value = !BoundBool.Value; } if (OnActivate != null) { OnActivate(this); } Main.EndCutsceneMode(); if (SaveSettingsOnHotkey) { Main.SaveSettings(); } return(true); } return(false); }
/// <summary> /// Verifica qual tecla está sendo segurada /// </summary> private void OnKeyDown() { foreach (var value in ExternalKey.acceptKey) { if (keyboardState.IsKeyDown(value)) { if (value.Equals(OpenTK.Input.Key.B)) { AddKey(Key.B); } if (value.Equals(OpenTK.Input.Key.P)) { AddKey(Key.P); } if (value.Equals(OpenTK.Input.Key.R)) { AddKey(Key.R); } if (value.Equals(OpenTK.Input.Key.G)) { AddKey(Key.G); } if (value.Equals(OpenTK.Input.Key.A)) { AddKey(Key.A); } if (value.Equals(OpenTK.Input.Key.M)) { AddKey(Key.M); } if (value.Equals(OpenTK.Input.Key.S)) { AddKey(Key.S); } if (value.Equals(OpenTK.Input.Key.N)) { AddKey(Key.N); } if (value.Equals(OpenTK.Input.Key.F)) { AddKey(Key.F); } if (value.Equals(OpenTK.Input.Key.ControlLeft)) { AddKey(Key.ControlLeft); } if (value.Equals(OpenTK.Input.Key.Space)) { AddKey(Key.Space); } if (value.Equals(OpenTK.Input.Key.Escape)) { AddKey(Key.Escape); } if ( value.Equals(OpenTK.Input.Key.BackSlash) || value.Equals(OpenTK.Input.Key.Delete) || value.Equals(OpenTK.Input.Key.Back) ) { AddKey(Key.Delete); } } } }
public static bool IsPressed(Key key) { return(_kbState.IsKeyDown(key)); }
private void Inputs() { OpenTK.Input.KeyboardState state = OpenTK.Input.Keyboard.GetState(); if (state.IsKeyDown(Key.Space) && lastKeystate.IsKeyUp(Key.Space)) { autoRotate = !autoRotate; } this.lastKeystate = state; if (state.IsKeyDown(Key.A)) { left = true; } if (state.IsKeyDown(Key.S)) { down = true; } if (state.IsKeyDown(Key.D)) { right = true; } if (state.IsKeyDown(Key.W)) { up = true; } if (state.IsKeyUp(Key.A)) { left = false; } if (state.IsKeyUp(Key.S)) { down = false; } if (state.IsKeyUp(Key.D)) { right = false; } if (state.IsKeyUp(Key.W)) { up = false; } if (state.IsKeyDown(Key.Right)) { xdist = -0.05f; cube.SetTranslation(xdist, 'x'); } if (state.IsKeyDown(Key.Left)) { xdist = 0.05f; cube.SetTranslation(xdist, 'X'); } if (state.IsKeyDown(Key.Up)) { ydist = 0.05f; cube.SetTranslation(ydist, 'Y'); } if (state.IsKeyDown(Key.Down)) { ydist = -0.05f; cube.SetTranslation(ydist, 'Y'); } if (state.IsKeyDown(Key.Escape)) { this.Exit(); } }
public static bool UpdateAllSlots(int shaderID, int mouseX, int mouseY, ref Inp.KeyboardState newKeyboardState, ref Inp.MouseState newMouseState, ref Inp.MouseState oldMouseState, MarbleSelection marbleSelection, Rectangle clientRectangle, Camera camera, ref Matrix4 projection, ref Matrix4 view, List <Marble> marbles, List <MarbleMove> moves, ref int undoLevel, bool spinningMarbles, bool animateMoves, ref Marble lastMarbleRemovedForWin) { if (Game.FlashTicksAreAscending) { Game.FlashTicks++; if (Game.FlashTicks > Game.MAX_FLASH_TICKS) { Game.FlashTicks -= 2; Game.FlashTicksAreAscending = false; } } else { Game.FlashTicks--; if (Game.FlashTicks < 0) { Game.FlashTicks = 1; Game.FlashTicksAreAscending = true; } } if (Selected != null) { SelectionAnimationTick++; if (SelectionAnimationTick > MAX_SELECTION_ANIMATION_TICK) { SelectionAnimationTick = 0; } } Marble oldSelected = Selected; for (int i = 1; i < Game.LIGHT_COUNT; i++) { Game.SetLightEnabled(shaderID, i, false); } HighlightedSlot = null; if (marbleSelection == MarbleSelection.None || (marbleSelection == MarbleSelection.Mouse && (mouseX < 0 || mouseY < 0 || mouseX > clientRectangle.Width || mouseY > clientRectangle.Height))) { foreach (Marble m in marbles) { m.Update(shaderID, spinningMarbles); } return(false); } Marble highlightedMarble = null; float closestMarbleDistance = float.MaxValue; float distance = float.NaN; //Vector2 mousePosNDC = MousePositionInNDC(); //float rotY = (float)Math.Atan(-mousePosNDC.Y * Math.Tan(VerticalFieldOfView / 2f)); //float rotX = -(float)Math.Atan(mousePosNDC.X * Math.Tan(HorizontalFieldOfView(VerticalFieldOfView) / 2f)); //float rot = (float)Math.Atan(mousePosNDC.Length * (float)Math.Tan(VerticalFieldOfView / 2f)); //float rotY = (float)Math.Atan(-mousePosNDC.Y * (float)Math.Tan(VerticalFieldOfView / 2f)); //float rotX = -(float)Math.Atan(mousePosNDC.X * (float)Math.Tan(HorizontalFieldOfView(VerticalFieldOfView) / 2f)); //Matrix4 xRotation = Matrix4.CreateFromAxisAngle(CameraUp(), rotX); //Vector3 ray = Vector3.Transform(CameraForward(), xRotation); //ray = Vector3.Transform(ray, Matrix4.CreateFromAxisAngle(CameraRight(), rotY)); //Vector3 ray = Vector3.TransformPerspective(CameraForward(), Matrix4.CreateFromAxisAngle(CameraUp(), rotX) * Matrix4.CreateFromAxisAngle(CameraRight(), rotY)); Vector3 ray; if (marbleSelection == MarbleSelection.Mouse) { ray = Utils.MousePickRay(mouseX, mouseY, clientRectangle, ref projection, ref view); } else { ray = camera.Forward; } bool pickHad = false; //Vector3 ray = Vector3.Transform(CameraForward(), Matrix4.CreateRotationZ(HorizontalFieldOfView(VerticalFieldOfView) / 2f)); //Vector3 ray = Vector3.Transform(CameraForward(), Matrix4.CreateRotationZ(MousePositionInNDC().X * -(float)Math.Tan(HorizontalFieldOfView(VerticalFieldOfView) / VerticalFieldOfView / MathHelper.PiOver2))); List <int> emptySlots = new List <int>(); for (int i = 0; i < STARTING_COUNT; i++) { emptySlots.Add(i); } Vector3 raySource = marbleSelection == MarbleSelection.Mouse ? camera.Position : camera.FocusPoint; foreach (Marble m in marbles) { if (!m.Alive) { continue; } emptySlots.Remove(m.PositionSlot); Vector3 marblePos = m.Position(); if (MouseIsOver(marblePos, 1f, raySource, ray, ref distance, closestMarbleDistance)) { pickHad = true; highlightedMarble = m; HighlightedSlot = m.PositionSlot; closestMarbleDistance = distance; } } if (Selected != null) { emptySlots.RemoveAll(i => !SlotIsValid(i, marbles)); foreach (int i in emptySlots) { if (MouseIsOver(Position(i), 0.375f, raySource, ray, ref distance, closestMarbleDistance)) { pickHad = true; highlightedMarble = null; HighlightedSlot = i; closestMarbleDistance = distance; } } if (!pickHad) { foreach (int i in emptySlots) { if (MouseIsOver(Position(i), 1f, raySource, ray, ref distance, closestMarbleDistance)) { //pickHad = true; HighlightedSlot = i; closestMarbleDistance = distance; } } } } bool moveMade = false; if (newMouseState.LeftButton == Inp.ButtonState.Pressed && oldMouseState.LeftButton == Inp.ButtonState.Released) { if (HighlightedSlot != null) { bool shift = newKeyboardState.IsKeyDown(Inp.Key.ShiftLeft) || newKeyboardState.IsKeyDown(Inp.Key.ShiftRight); //marbles.Remove(GetMarbleInSlot(HighlightedSlot.Value, marbles)); Marble marbleToBeRemoved; if (!shift && marbles.Count(m => m.Alive) == STARTING_COUNT) { if (animateMoves) { highlightedMarble.AnimateFromSlot = highlightedMarble.PositionSlot; highlightedMarble.AnimationTick = MAX_ANIMATION_TICKS; highlightedMarble.AnimatingAsInitialRemoval = true; } highlightedMarble.Alive = false; if (undoLevel > 0) { moves.RemoveRange(moves.Count - undoLevel, undoLevel); undoLevel = 0; } moves.Add(new MarbleMove(highlightedMarble.PositionSlot, -1, -1, highlightedMarble.Type)); } else if (SlotIsValid(HighlightedSlot.Value, marbles, out marbleToBeRemoved)) { // Remove a marble if (undoLevel > 0) { moves.RemoveRange(moves.Count - undoLevel, undoLevel); undoLevel = 0; } moves.Add(new MarbleMove(Selected.PositionSlot, marbleToBeRemoved.PositionSlot, HighlightedSlot.Value, marbleToBeRemoved.Type)); if (animateMoves) { Selected.AnimateFromSlot = Selected.PositionSlot; Selected.AnimationTick = 0; marbleToBeRemoved.AnimateFromSlot = marbleToBeRemoved.PositionSlot; marbleToBeRemoved.AnimationTick = 0; } Selected.PositionSlot = HighlightedSlot.Value; marbleToBeRemoved.Alive = false; moveMade = true; //if (!Selected.CanMove(marbles)) Selected = null; if (marbles.Count(m => m.Alive) == 1) { lastMarbleRemovedForWin = marbleToBeRemoved; } } else if (shift) { camera.FocusPoint = highlightedMarble.Position(); } else if (highlightedMarble == Selected) { Selected = null; } else { Selected = highlightedMarble; } } else { Selected = null; } } foreach (Marble m in marbles) { m.Update(shaderID, spinningMarbles); } if (Selected != oldSelected) { SelectionAnimationTick = 0; } return(moveMade); }