本文整理汇总了C#中Microsoft.Xna.Framework.Input.KeyboardState.GetPressedKeys方法的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState.GetPressedKeys方法的具体用法?C# KeyboardState.GetPressedKeys怎么用?C# KeyboardState.GetPressedKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Input.KeyboardState
的用法示例。
在下文中一共展示了KeyboardState.GetPressedKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update()
{
if (doInitDelay)
{
initialDelay--;
}
if (initialDelay <= 0)
{
doInitDelay = false;
currentCommand = new NullCommand();
keyboardState = Keyboard.GetState();
foreach (Keys key in keyboardState.GetPressedKeys())
{
if (commandLibrary.ContainsKey(key))
{
currentCommand = commandLibrary[key];
currentCommand.Execute();
break;
}
}
if (keyboardState.GetPressedKeys().Length == 0)
{
player.Idle();
}
}
}
示例2: SetKeyboardState
public void SetKeyboardState(KeyboardState ob)
{
if(ob.GetPressedKeys().Length>0)
switch (ob.GetPressedKeys()[0])
{
case Keys.W:
direction = GameObjects.Sprites.Direction.Up;
action = GameObjects.Sprites.Action.Walking;
break;
case Keys.A:
direction = GameObjects.Sprites.Direction.Left;
action = GameObjects.Sprites.Action.Walking;
break;
case Keys.S:
direction = GameObjects.Sprites.Direction.Down;
action = GameObjects.Sprites.Action.Walking;
break;
case Keys.D:
direction = GameObjects.Sprites.Direction.Right;
action = GameObjects.Sprites.Action.Walking;
break;
default:
action = GameObjects.Sprites.Action.Standing;
break;
}
if (!ob.GetPressedKeys().Contains(Keys.W) &&
!ob.GetPressedKeys().Contains(Keys.A) &&
!ob.GetPressedKeys().Contains(Keys.S) &&
!ob.GetPressedKeys().Contains(Keys.D))
{
action = GameObjects.Sprites.Action.Standing;
}
}
示例3: Update
public void Update(KeyboardState Tastenstatus, ref string Text)
{
if (SchreibModus == true)
{
Lastposition = Text.Length;
if (Tastenstatus.IsKeyDown(Keys.LeftShift))
{
Großschreiben = true;
if (Tastendruck == true && Tastenstatus.GetPressedKeys().Length == 1)
{
Tastendruck = false;
}
}
else
{
Großschreiben = false;
if (Tastendruck == true && Tastenstatus.GetPressedKeys().Length == 0)
{
Tastendruck = false;
}
}
if (Tastenstatus.IsKeyDown(Keys.Back) && Lastposition > 0 && Tastendruck == false)
{
Text = Text.Remove(Lastposition - 1, 1);
Tastendruck = true;
}
if (Lastposition <= MaxAnzahlZeichen)
{
Keys[] currentlyPressed = Tastenstatus.GetPressedKeys();
List<string> allowedChars = new List<string>(AllowedChars);
foreach (Keys key in currentlyPressed)
{
Buchstabe = key.ToString();
if (Buchstabe.Length == 2)
{
Buchstabe = Buchstabe.Remove(0, 1);
}
if (allowedChars.Contains(Buchstabe.ToLower()) && Tastendruck == false)
{
Tastendruck = true;
if (Großschreiben == true)
{
Text += Buchstabe.ToUpper();
}
else
{
Text += Buchstabe.ToLower();
}
}
}
}
}
}
示例4: HandleInput
public override void HandleInput(GameTime time)
{
//throw new NotImplementedException();
newState = Keyboard.GetState();
Keys[] newDown = newState.GetPressedKeys();
Keys[] oldDown = oldState.GetPressedKeys();
foreach(Keys k in oldDown)
{
if(!newDown.Contains(k))
{
if(k == Keys.Back)
{
if (text.Length > 0) text = text.Substring(0, text.Length - 1);
}
else if(k == Keys.Space)
{
text += " ";
}
else
{
text += k.ToString();
}
}
}
oldState = newState;
}
示例5: UpdateInput
public static void UpdateInput()
{
oldKeyboardState = currentKeyboardState;
currentKeyboardState = Keyboard.GetState();
Keys[] pressedKeys;
pressedKeys = currentKeyboardState.GetPressedKeys();
foreach (Keys key in pressedKeys)
{
if( oldKeyboardState.IsKeyUp(key) )
{
if (key == Keys.Back) // overflows
{
if (textString.Length > 0)
textString = textString.Remove(textString.Length - 1, 1);
}
else if (key == Keys.Space)
textString = textString.Insert(textString.Length, " ");
else if (key == Keys.Enter)
{
Command = textString;
InputParser.Update();
textString = String.Empty;
}
else
textString += key.ToString();
}
}
}
示例6: Update
public void Update(GameTime time)
{
oldState = currentState;
currentState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
shiftDown = currentState.IsKeyDown(Keys.LeftShift) || currentState.IsKeyDown(Keys.RightShift);
currentlyPressed = currentState.GetPressedKeys();
previouslyPressed = oldState.GetPressedKeys();
if (currentlyPressed.Length != previouslyPressed.Length)
{
keyHoldTimer = 0.0f;
keyHeld = false;
lastKeyHeld = FindLastKeyPressed();
}
if (!keyHeld && currentlyPressed.Length > 0)
{
keyHoldTimer += (float)time.ElapsedGameTime.TotalMilliseconds;
if (keyHoldTimer > keyHoldWait)
{
keyHeld = true;
}
}
}
示例7: ReturnDigitORNumberKeyAsChar
public List<char> ReturnDigitORNumberKeyAsChar(KeyboardState keyboardstate, KeyboardState oldKeyboardstate)
{
List<char> chars = new List<char>();
char c;
bool shift = false;
if (keyboardstate.IsKeyDown(Keys.LeftShift) || keyboardstate.IsKeyDown(Keys.RightShift))
shift = true;
foreach (Keys a in keyboardstate.GetPressedKeys())
{
if (oldKeyboardstate.IsKeyUp(a) && a != Keys.RightShift && a != Keys.LeftShift)
{
int i = a.GetHashCode();
c = (char)i;
if (Char.IsLetterOrDigit(c))
if (shift)
chars.Add(c);
else
chars.Add(Convert.ToChar(c.ToString().ToLower()));
}
}
return chars;
}
示例8: Initialize
public static void Initialize()
{
previousState = currentState = Keyboard.GetState();
previousKeySet = new HashSet<Keys>(currentState.GetPressedKeys());
keyListeners = new HashSet<KeyListener>();
}
示例9: Update
public void Update(KeyboardState state)
{
Keys[] pressed = state.GetPressedKeys();
List<Keys> toRemove = new List<Keys>();
List<Keys> toRelease = new List<Keys>();
foreach (KeyValuePair<Keys, AdvancedKeyState> key in States) {
if (!pressed.Contains(key.Key)) {
if (key.Value == AdvancedKeyState.Pressed ||
key.Value == AdvancedKeyState.Down) {
toRelease.Add(key.Key);
} else if (key.Value == AdvancedKeyState.Released) {
toRemove.Add(key.Key);
}
}
}
foreach (var release in toRelease) {
States[release] = AdvancedKeyState.Released;
FireEvent(release);
}
foreach (var remove in toRemove)
States.Remove(remove);
foreach (var key in pressed) {
if (!States.ContainsKey(key) ||
States[key] == AdvancedKeyState.Released) {
States[key] = AdvancedKeyState.Pressed;
FireEvent(key);
} else if (States[key] == AdvancedKeyState.Pressed) {
States[key] = AdvancedKeyState.Down;
}
}
}
示例10: TypeText
public static string TypeText(KeyboardState oldState, KeyboardState newState, string text, int maxchars, string def)
{
Keys[] oldKeys = oldState.GetPressedKeys();
Keys[] newKeys = newState.GetPressedKeys();
foreach (Keys key in oldKeys)
{
if (!newKeys.Contains(key))
{
if (key == Keys.Back)
{
if (text.Length > 0)
text = text.Remove(text.Length - 1);
}
else if (text.Length <= maxchars)
{
if (key == Keys.Space)
{
text += "_";
}
else if (key.ToString().Length == 1)
{
if (text == def)
text = "";
text += key.ToString();
}
}
}
}
return text;
}
示例11: getState
public static void getState()
{
oldTeclado = teclado;
oldMouse = mouse;
teclado = Keyboard.GetState();
mouse = Mouse.GetState();
Keys[] keys = teclado.GetPressedKeys();
foreach (Keys keyPressed in keys)
{
if (!keysPressed.Contains(keyPressed))
{
keysPressed.Add(keyPressed);
}
}
foreach (Keys keyPressed in keysPressed)
{
if (teclado.IsKeyUp(keyPressed))
{
keysPressed.Remove(keyPressed);
break;
}
}
}
示例12: Update
public void Update(GameTime gameTime, KeyboardState keyState)
{
if (IsAtive)
{
#region Change of direction
if (keyState.GetPressedKeys().Contains(KeyLeft))
{
this.Direction += DirectionSpeed * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
}
if (keyState.GetPressedKeys().Contains(KeyRight))
{
this.Direction -= DirectionSpeed * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
}
#endregion
Vector2 newPosition = ActualPosition + new Vector2((float)Math.Sin(Direction) * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds, (float)Math.Cos(Direction) * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds);
float Distance = Vector2.Distance(newPosition, Positions[Positions.Count - 1]);
if (SpaceParts <= 0)
{
for (int i = (int)(Distance / PartsDistance); i > 0; i--)
{
Vector2 newPart = Positions[Positions.Count - 1] + new Vector2((float)Math.Sin(Direction) * PartsDistance, (float)Math.Cos(Direction) * PartsDistance);
Positions.Add(newPart);
}
}
else
{
SpaceParts--;
if (SpaceParts == 0)
{
Positions.Add(ActualPosition);
}
}
ActualPosition = newPosition;
#region Spaces
SpaceTime -= gameTime.ElapsedGameTime.TotalMilliseconds;
if (SpaceTime <= 0)
{
SpaceParts = SpacePartsMax;
SpaceTime = 2000 + Nahoda.Next(0, 3000);
}
#endregion
}
}
示例13: DevInput
private static void DevInput(MouseState mouse, KeyboardState keyboard)
{
if (keyboard.GetPressedKeys().Contains(Keys.Space))
{
Camera.Position.X = 0;
Camera.Position.Z = 0;
}
}
示例14: CalculateKeyDownMessages
private void CalculateKeyDownMessages(KeyboardState newKeyState)
{
var keys = newKeyState.GetPressedKeys().Where(key => !_oldKeyState.IsKeyDown(key));
foreach (var key in keys)
{
_messageManager.QueueMessage(new KeyDownMessage(key));
}
}
示例15: Update
public override void Update(GameTime gameTime)
{
keyOldState = keyNewState;
keyNewState = Keyboard.GetState();
if ((Game.IsActive && (keyNewState.GetPressedKeys().Length > 0 || keyOldState.GetPressedKeys().Length > 0) && KeyEvent != null))
KeyEvent(keyNewState, keyOldState);
}