本文整理汇总了C#中KeyboardState.IsKeyDown方法的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState.IsKeyDown方法的具体用法?C# KeyboardState.IsKeyDown怎么用?C# KeyboardState.IsKeyDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyboardState
的用法示例。
在下文中一共展示了KeyboardState.IsKeyDown方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsKeyDownAndChanged
private bool IsKeyDownAndChanged(KeyboardState keyState, Keys key)
{
bool keyDown = keyState.IsKeyDown(key);
bool changed = keyDown != _oldState.IsKeyDown(key);
return (keyDown && changed);
}
示例2: processKeyboardInput
public void processKeyboardInput(KeyboardState state)
{
if (state.IsKeyDown(Key.W))
{
Pos += (Target * stepSize);
}
if (state.IsKeyDown(Key.S))
{
Pos -= (Target * stepSize);
}
if (state.IsKeyDown(Key.A))
{
Vector3 Left = Vector3.Cross(Target, Up);
Left.Normalize();
Left *= stepSize;
Pos += Left;
}
if (state.IsKeyDown(Key.D))
{
Vector3 Right = Vector3.Cross(Up, Target);
Right.Normalize();
Right *= stepSize;
Pos += Right;
}
/* Mouse movement code temporarily mapped to arrow keys */
bool shouldUpdate = false;
if (state.IsKeyDown(Key.Left))
{
angleH -= 0.1f;
shouldUpdate = true;
}
else if (state.IsKeyDown(Key.Right))
{
angleH += 0.1f;
shouldUpdate = true;
}
if (state.IsKeyDown(Key.Up))
{
if (angleV > -90.0f)
{
angleV -= 0.1f;
shouldUpdate = true;
}
}
else if (state.IsKeyDown(Key.Down))
{
if (angleV < 90.0f)
{
angleV += 0.1f;
shouldUpdate = true;
}
}
if (shouldUpdate)
{
update();
}
}
示例3: Move
//Methods from IMovable
public void Move(KeyboardState keyBoardState)
{
keyBoardState = Keyboard.GetState();
this.Velocity = Vector2.Zero;
if (keyBoardState.IsKeyDown(Keys.Up))
{
this.velocity.Y = -movementSpeed.Y;
}
if (keyBoardState.IsKeyDown(Keys.Left))
{
this.velocity.X = -movementSpeed.X;
}
if (keyBoardState.IsKeyDown(Keys.Down))
{
this.velocity.Y = movementSpeed.Y;
}
if (keyBoardState.IsKeyDown(Keys.Right))
{
this.velocity.X = movementSpeed.X;
}
this.Position += this.velocity;
}
示例4: HandleInput
private void HandleInput()
{
currentKeyboard = Keyboard.GetState();
// Set culling mode
if (currentKeyboard.IsKeyDown(Keys.F1))
{
if (!previousKeyboard.IsKeyDown(Keys.F1))
{
cullingModeOn = !cullingModeOn;
}
}
// Check for exit.
if (currentKeyboard.IsKeyDown(Keys.Escape))
{
Exit();
}
// Fullscreen on/off toggle
if (currentKeyboard.IsKeyDown(Keys.F11))
{
// If not down last update, key has just been pressed.
if (!previousKeyboard.IsKeyDown(Keys.F11))
{
fullscreenMode = !fullscreenMode;
SetScreenMode();
}
}
// Seated on/off toggle
if (currentKeyboard.IsKeyDown(Keys.V))
{
if (!previousKeyboard.IsKeyDown(Keys.V))
{
chooser.SeatedMode = !chooser.SeatedMode;
skeletonDetected = false;
}
}
// Near mode on/off toggle
if (currentKeyboard.IsKeyDown(Keys.N))
{
if (!previousKeyboard.IsKeyDown(Keys.N))
{
chooser.NearMode = !chooser.NearMode;
skeletonDetected = false;
}
}
// Reset the avatar filters (also resets camera)
if (currentKeyboard.IsKeyDown(Keys.R))
{
if (!previousKeyboard.IsKeyDown(Keys.R))
{
}
}
// Рисовать bounding boxes вкл/выкл
if (currentKeyboard.IsKeyDown(Keys.B))
{
if (!previousKeyboard.IsKeyDown(Keys.B))
{
drawBoundingBoxesOn = !drawBoundingBoxesOn;
}
}
}
示例5: handleKeyboard
protected void handleKeyboard(float dt)
{
keystate = Keyboard.GetState();
/* Lateral movement */
if (keystate.IsKeyDown(Key.W))
position += forward * speed * dt;
if (keystate.IsKeyDown(Key.S))
position -= forward * speed * dt;
if (keystate.IsKeyDown(Key.A))
position -= right * speed * dt;
if (keystate.IsKeyDown(Key.D))
position += right * speed * dt;
/* Fly up/down */
if (keystate.IsKeyDown(Key.Space))
position.Y += speed * dt;
if (keystate.IsKeyDown(Key.LShift))
position.Y -= speed * dt;
/* Keyboard turn */
if (keystate.IsKeyDown(Key.Left))
yaw -= keyTurnSpeed * dt;
if (keystate.IsKeyDown(Key.Right))
yaw += keyTurnSpeed * dt;
if (keystate.IsKeyDown(Key.Up))
pitch += keyTurnSpeed * dt;
if (keystate.IsKeyDown(Key.Down))
pitch -= keyTurnSpeed * dt;
}