public KeyboardState KState() { try { return(keysDev.GetCurrentKeyboardState()); //return the current key } catch { try { keysDev.Acquire(); return(keysDev.GetCurrentKeyboardState()); //try to regain the device if there is an input error } catch (InputException ex) { //catch an error while regaining the device if (ex is OtherApplicationHasPriorityException || ex is NotAcquiredException) { return(null); //if those excpetions occur return nothing as the device is not ready now } return(null); } } }
private void ReadMouse() { MouseState state = mouse.CurrentMouseState; mousepos.X = state.X; mousepos.Y = state.Y; mousepos.Z = state.Z; byte[] buttons = state.GetMouseButtons(); if (buttons[1] != 0) //right button { float mx = mouse.CurrentMouseState.X; float my = mouse.CurrentMouseState.Y; //for the pen input, it goes insainly fast if (Math.Abs(mousepos.X) > 10) { //mousepos.X = mousepos.X%10; } if (Math.Abs(mousepos.Y) > 10) { //mousepos.Y = mousepos.Y%10; } theta += Geometry.DegreeToRadian(mousepos.X); phi += Geometry.DegreeToRadian(mousepos.Y); } if (mousepos.Z > 0) //scroll wheel { if (keyboard.GetCurrentKeyboardState()[Key.LeftControl]) { spacing -= .1f; } else { rho -= 1; } } else if (mousepos.Z < 0) { if (keyboard.GetCurrentKeyboardState()[Key.LeftControl]) { spacing += .1f; } else { rho += 1; } } if (buttons[2] != 0) //middle button { if (!middle) { rubixCube.Scramble(); } } middle = buttons[2] == 0; //mouse. }
/// <summary> /// this function gives values to the mouse position for use later. /// this also makes sure the user cant break the code by making the mouse /// go places i dont want them to. /// this also does the zooming functions on the scroll wheel and when pressed down will scramble. /// </summary> private void ReadMouse() { MouseState state = mouse.CurrentMouseState; mousepos.X = state.X; mousepos.Y = state.Y; mousepos.Z = state.Z; byte[] buttons = state.GetMouseButtons(); if (buttons[1] != 0) //right button { float mx = mouse.CurrentMouseState.X; float my = mouse.CurrentMouseState.Y; //for the pen input, it goes insainly fast if (Math.Abs(mousepos.X) > 10) { mousepos.X = mousepos.X % 10; } if (Math.Abs(mousepos.Y) > 10) { mousepos.Y = mousepos.Y % 10; } theta += Geometry.DegreeToRadian(mousepos.X); phi += Geometry.DegreeToRadian(mousepos.Y); } float Dif = mousepos.Z - OldZ; OldZ = mousepos.Z; if (Dif != 0) //scroll wheel { if (keyboard.GetCurrentKeyboardState()[Key.LeftControl]) { spacing -= 0.0005f * Dif; Console.WriteLine("rho = " + rho + " phi = " + phi + " theta = " + theta + " spacing = " + spacing); } else { rho += 0.005 * Dif; } } if (buttons[2] != 0) //middle button { if (!middle) { rubixCube.Scramble(); } } middle = buttons[2] == 0; //mouse. }
private void UpdatePOV() { ptCurrentMousePosit.X = Cursor.Position.X; ptCurrentMousePosit.Y = Cursor.Position.Y; Vector3 currentLookAt = pov.LookAt; if (mousing) { Matrix matRotation = Matrix.RotationAxis(pov.Right, Geometry.DegreeToRadian((float)(ptCurrentMousePosit.Y - ptLastMousePosit.Y) / 3.0f)) + Matrix.RotationAxis(pov.Up, Geometry.DegreeToRadian((float)(ptCurrentMousePosit.X - ptLastMousePosit.X) / 3.0f)); pov.Look = Vector3.TransformCoordinate(pov.Look, matRotation); } ptLastMousePosit.X = ptCurrentMousePosit.X; ptLastMousePosit.Y = ptCurrentMousePosit.Y; if (dinputDevice != null) { KeyboardState keys = dinputDevice.GetCurrentKeyboardState(); // Up Arrow Key - View moves forward if (keys[Key.Up]) { pov.Eye += pov.StraightOn * moveSpeed * elapsedTime; } // Down Arrow Key - View moves backward if (keys[Key.Down]) { pov.Eye -= pov.StraightOn * moveSpeed * elapsedTime; } // Left Arrow Key - View side-steps or strafes to the left if (keys[Key.Left]) { pov.Eye -= pov.Right * moveSpeed * elapsedTime; } // Right Arrow Key - View side-steps or strafes to the right if (keys[Key.Right]) { pov.Eye += pov.Right * moveSpeed * elapsedTime; } // Home Key - View elevates up if (keys[Key.Home]) { pov.Eye += pov.Up * moveSpeed * elapsedTime; } // End Key - View elevates down if (keys[Key.End]) { pov.Eye -= pov.Up * moveSpeed * elapsedTime; } } }
private void HandleInput() { // Handle mouse if (mouseDown) { int x = Cursor.Position.X; int y = Cursor.Position.Y; x -= lastMousePosition.X; y -= lastMousePosition.Y; lastMousePosition = Cursor.Position; camera.Rotate(x, y); } // Handle keys KeyboardState keys = keyboard.GetCurrentKeyboardState(); Vector3 move = new Vector3(); if (keys[Key.UpArrow]) { move += new Vector3(0f, 0f, 1f); } if (keys[Key.DownArrow]) { move += new Vector3(0f, 0f, -1f); } if (keys[Key.LeftArrow]) { move += new Vector3(1f, 0f, 0f); } if (keys[Key.RightArrow]) { move += new Vector3(-1f, 0f, 0f); } if (keys[Key.PageUp]) { move += new Vector3(0f, 1f, 0f); } if (keys[Key.PageDown]) { move += new Vector3(0f, -1f, 0f); } if (this.Focused) { camera.Move(move); } }
internal void updateKeyboard() { KeyboardState state = keyboardDevice.GetCurrentKeyboardState(); //Hacer copia del estado actual Array.Copy(currentkeyboardState, previouskeyboardState, currentkeyboardState.Length); //Actualizar cada tecla del estado actual for (int i = 0; i < currentkeyboardState.Length; i++) { Key k = (Key)(i + 1); currentkeyboardState[i] = state[k]; } }
/// <summary> /// 程序主流程 /// </summary> public void Play() { KeyboardState kbState = kbDevice.GetCurrentKeyboardState(); Vector3 vec = Vector3.Empty; if (kbState[Key.W]) { vec += new Vector3(0, -1, 0); } if (kbState[Key.A]) { vec += new Vector3(-1, 0, 0); } if (kbState[Key.S]) { vec += new Vector3(0, 1, 0); } if (kbState[Key.D]) { vec += new Vector3(1, 0, 0); } float passTick = TimerUtils.CPUTick(); if (passTick > 0) { TimerUtils.Update(passTick); } //刷新帧 frameTick += passTick; if (frameTick > PerFrameTick) { int a = 0; while (frameTick > PerFrameTick) { //===== a++; //===== frameTick -= PerFrameTick; totalFrameCount++; UpdateFrame(PerFrameTick); } Render(); } }
private void ReadKeyboard() { KeyboardState keys = keyb.GetCurrentKeyboardState(); if (keys[Key.Delete]) { worldMatrix = Matrix.RotationYawPitchRoll(0.03f, 0, 0) * worldMatrix; } if (keys[Key.Next]) { worldMatrix = Matrix.RotationYawPitchRoll(-0.03f, 0, 0) * worldMatrix; } if (keys[Key.Home]) { worldMatrix = Matrix.RotationYawPitchRoll(0, 0.03f, 0) * worldMatrix; } if (keys[Key.End]) { worldMatrix = Matrix.RotationYawPitchRoll(0, -0.03f, 0) * worldMatrix; } if (keys[Key.Insert]) { worldMatrix = Matrix.RotationYawPitchRoll(0, 0, 0.03f) * worldMatrix; } if (keys[Key.PageUp]) { worldMatrix = Matrix.RotationYawPitchRoll(0, 0, -0.03f) * worldMatrix; } if (keys[Key.W]) { worldMatrix = worldMatrix * Matrix.Translation(0, 0, 0.2f); } if (keys[Key.S]) { worldMatrix = worldMatrix * Matrix.Translation(0, 0, -0.2f); } if (keys[Key.Space]) { //foreach (Object3D obj in objList) // obj.Step(); } }
static public bool GetAsyncKeyStateB(Key key) { if (mbPaused) { return(false); } if (HasFocus() == false) { return(false); } if (null != mInputDevice) { KeyboardState state = mInputDevice.GetCurrentKeyboardState(); return(state[key]); } return(false); }
private void ReadKeyboard() { KeyboardState keys = keyb.GetCurrentKeyboardState(); if (keys[Key.RightArrow]) { MyMaticeX += 0.5f; } if (keys[Key.LeftArrow]) { MyMaticeX -= 0.5f; } if (keys[Key.UpArrow]) { MyMaticeY += 0.5f; } if (keys[Key.DownArrow]) { MyMaticeY -= 0.5f; } }
private void ReadKeyboard() { KeyboardState keys = keyb.GetCurrentKeyboardState(); if (keys[Key.UpArrow]) { velocity.Y -= 2; } if (keys[Key.DownArrow]) { velocity.Y += 2; } if (keys[Key.RightArrow]) { velocity.X += 2; } if (keys[Key.LeftArrow]) { velocity.X -= 2; } }
public void GetCurrentKeyboardState() { keyState = device.GetCurrentKeyboardState(); }
} // inicializarTeclado().fim // [--- void verificarTeclado() { string sInfo = "prj_Teclado02 - Teclas pressionadas: "; // Variáveis para guardar o estado das teclas int seta_esquerda = 0; int seta_direita = 0; int seta_cima = 0; int seta_abaixo = 0; // Verifica estado do teclado DirectInput.KeyboardState estadoTeclado; estadoTeclado = teclado.GetCurrentKeyboardState(); // Atualizado estados das variáveis de teclas if (estadoTeclado[DirectInput.Key.DownArrow]) { seta_abaixo = 1; } if (estadoTeclado[DirectInput.Key.UpArrow]) { seta_cima = 1; } if (estadoTeclado[DirectInput.Key.LeftArrow]) { seta_esquerda = 1; } if (estadoTeclado[DirectInput.Key.RightArrow]) { seta_direita = 1; } if (estadoTeclado[DirectInput.Key.RightShift]) { xcol = 320; } if (estadoTeclado[DirectInput.Key.RightShift]) { ylin = 240; } if (estadoTeclado[DirectInput.Key.Escape]) { terminar = true; } // Atualiza posicionamento do 'jogador' if (seta_abaixo == 1) { ylin += 5; } if (seta_cima == 1) { ylin -= 5; } if (seta_esquerda == 1) { xcol -= 5; } if (seta_direita == 1) { xcol += 5; } // Muda 'jogador' conforme seta pressionada if (seta_esquerda == 1) { jogador = "<(-:"; } if (seta_direita == 1) { jogador = ":-)>"; } this.Text = sInfo; // Processa a tecla Escape if (terminar) { device.Dispose(); teclado.Dispose(); this.Close(); Application.Exit(); } // endif } // verificarTeclado()
// hot keys defined private void ReadKeyboard() { try { keyb.Acquire(); KeyboardState keys = keyb.GetCurrentKeyboardState(); if (keys[Key.RightArrow] || keys[Key.A]) { //LeftRightOffset += 1000; LeftRightOffset += (zoom) / 40f; } if (keys[Key.LeftArrow] || keys[Key.D]) { // LeftRightOffset -= 1000; LeftRightOffset -= (zoom) / 40f; } if (keys[Key.UpArrow] || keys[Key.W]) { UpDownOffset -= (zoom) / 40f; } if (keys[Key.DownArrow] || keys[Key.S]) { UpDownOffset += (zoom) / 40f; } // reset if (keys[Key.NumPad1]) { //UpDownOffset = 400; //LeftRightOffset = 800; //zoom = -1000; UpDownOffset = cUpDownOffset; LeftRightOffset = cLeftRightOffset; zoom = czoom; //runTimeMs += 1; } if (keys[Key.NumPad2]) { LeftRightOffset = 12644; UpDownOffset = 10159; zoom = -25313; } if (keys[Key.NumPad3]) { LeftRightOffset = 120994; UpDownOffset = 10125; zoom = -27287; } if (keys[Key.NumPad9]) { SorterRun = 1; // turn on stat loger for links per sec LinkRate_Stop = 0; LinkRate_CountPerSec = 0; } if (keys[Key.NumPad8]) { SorterRun = 0; } } catch { } //MouseState CurrentMouseState double d; try { mkeyb.Acquire(); MouseState mKeys = mkeyb.CurrentMouseState; byte[] b = mKeys.GetMouseButtons(); if (mKeys.Z > 0) { //zoom += 5000; d = zoom; zoom -= (int)zoom * 0.05f; } if (mKeys.Z < 0) { //zoom -= 5000; zoom += (int)zoom * 0.05f; } if (b[0] == 128) // left click { //UpDownOffset = cUpDownOffset; //LeftRightOffset = cLeftRightOffset; //zoom = czoom; } //mouse_x = mKeys.x; } catch { } }
/// <summary> /// Updates the keyboard device. /// </summary> public void Update() { _state = _device.GetCurrentKeyboardState(); }