public static void Poll() { KeyboardState kstate = keyboard.GetCurrentState(); foreach (Key k in kstate.AllKeys) { if (kstate.IsPressed(k)) { keyStates[k] = true; } if (kstate.IsReleased(k)) { keyStates[k] = false; } } MouseState mState = mouseRel.GetCurrentState(); LMBPressed = mState.GetButtons()[0]; RMBPressed = mState.GetButtons()[1]; MMBPressed = mState.GetButtons()[2]; mouseDeltaPos = new Vector3(mState.X, mState.Y, mState.Z); mouseAbsPosNormalized.X = (Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).X - (Renderer.viewport.Width / 2F)) / (float)Renderer.viewport.Width; mouseAbsPosNormalized.Y = (Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).Y - (Renderer.viewport.Height / 2F)) / (float)Renderer.viewport.Height; mouseAbsPosScreen.X = Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).X; mouseAbsPosScreen.Y = Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).Y; }
//----------------------------------------------------------------------- public bool IsKeyUp(int keycode) { // Returns true if the key is currently being pressed var key = (SlimDX.DirectInput.Key)keycode; bool up = KeyState.IsReleased(key) && !MyKeyDown[keycode]; return(up); }
public bool GetKey(Key key, int mode = 2) { keys_new.IsPressed(Key.D1); switch (mode) { case 0: //down return(keys_new.IsPressed(key) && keys_old.IsReleased(key)); case 1: //up return(keys_new.IsReleased(key) && keys_old.IsPressed(key)); default: //raw return(keys_new.IsPressed(key)); } }
private void Update() { Time += 0.001f; if (Time > Math.PI * 2.0) { Time -= (float)(Math.PI * 2.0); } Log.Instance.Update(); // get input Input.Instance.Update(); // gui scaling GuiScaling.Instance.Update(); // handle input KeyboardState keyboardState = Input.Instance.CurrentInput.KeyboardState; KeyboardState prevKeyboardState = Input.Instance.LastInput.KeyboardState; MouseState mouseState = Input.Instance.CurrentInput.MouseState; if (prevKeyboardState.IsPressed(Key.O) && keyboardState.IsReleased(Key.O)) { OpenGui(new GuiOptionsForm()); } if (prevKeyboardState.IsPressed(Key.P) && keyboardState.IsReleased(Key.P)) { OpenGui(new GuiDebugForm()); } if (prevKeyboardState.IsPressed(Key.F11) && keyboardState.IsReleased(Key.F11)) { GlobalRenderer.Instance.ToggleFullScreen(); } if (prevKeyboardState.IsPressed(Key.Escape) && keyboardState.IsReleased(Key.Escape) && Mode == GameMode.Gui) { CloseGui(); } else if (keyboardState.IsReleased(Key.V) && prevKeyboardState.IsPressed(Key.V)) { p.ToggleReport(); } else if (keyboardState.IsReleased(Key.C) && prevKeyboardState.IsPressed(Key.C)) { showProfiler = !showProfiler; } else if (keyboardState.IsReleased(Key.Z) && prevKeyboardState.IsPressed(Key.Z)) { p.ToggleMarkedSection(); } else if (keyboardState.IsReleased(Key.X) && prevKeyboardState.IsPressed(Key.X)) { p.SelectedSection = p.MarkedSection; } else if (keyboardState.IsReleased(Key.Backspace) && prevKeyboardState.IsPressed(Key.Backspace)) { int index = p.SelectedSection.LastIndexOf("."); if (index >= 0) { p.SelectedSection = p.SelectedSection.Substring(0, index); } } p.StartSection("2dgui"); if (ActiveGui != null) { ActiveGui.Update(); } p.EndSection(); // update world World.Instance.Update(); // reset mouse System.Windows.Forms.Cursor.Position = form.PointToScreen(new Point(Width / 2, Height / 2)); System.Windows.Forms.Cursor.Hide(); // update global game clock CurrentTick++; }
/// <summary> /// Checks for a trigger. /// </summary> public static bool IsTrigger(Key key) { return(s_thisState.IsPressed(key) && !s_lastFrameState.IsReleased(key)); }
public bool WasKeyReleased(Key key) { return(_keyboardStateLast.IsReleased(key)); }
public bool IsKeyReleased(Key key) { return(_keyboardStateCurrent.IsReleased(key)); }
private void GetInput(object obj) { var timer = Stopwatch.StartNew(); lock (this.devicesLock) { var newPush = new List <Tuple <Guid, int> >(); foreach (Device d in this.devices) { if (d.Poll().IsFailure) { d.Unacquire(); d.Dispose(); Debug.WriteLine("joy.Poll().IsFailure"); continue; } if (d is Joystick) { var joy = d as Joystick; JoystickState state = new JoystickState(); if (joy.GetCurrentState(ref state).IsFailure) { Debug.WriteLine("joy.GetCurrentState( ref state ).IsFailure"); continue; } bool[] buttons = state.GetButtons(); for (int i = 0; i < buttons.Length; i++) { Tuple <Guid, int> key = new Tuple <Guid, int>(joy.Information.InstanceGuid, i + 1); if (buttons[i] && !this.pushingKeys.Contains(key)) { newPush.Add(key); } else if (!buttons[i] && this.pushingKeys.Contains(key)) { this.pushingKeys.Remove(key); Released(key); } } } else if (d is Keyboard) { var board = d as Keyboard; KeyboardState state = new KeyboardState(); if (board.GetCurrentState(ref state).IsFailure) { continue; } foreach (var item in state.AllKeys) { Tuple <Guid, int> key = new Tuple <Guid, int>(board.Information.InstanceGuid, (int)item); if (state.IsPressed(item) && !this.pushingKeys.Contains(key)) { newPush.Add(key); } else if (state.IsReleased(item) && this.pushingKeys.Contains(key)) { this.pushingKeys.Remove(key); Released(key); } } } newPush.Shuffle(); if (newPush.Count > 0) { Debug.WriteLine("同時押し数 : " + newPush.Count); } foreach (var key in newPush) { this.pushingKeys.Add(key); Pushed(key); } } var dev = this.devices.FirstOrDefault(d => d.Disposed); while (dev != null) { this.devices.Remove(dev); dev = this.devices.FirstOrDefault(d => d.Disposed); } } timer.Stop(); this.UpdateTime = timer.ElapsedTicks; }