本文整理汇总了C#中Microsoft.Xna.Framework.Input.KeyboardState.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState.GetHashCode方法的具体用法?C# KeyboardState.GetHashCode怎么用?C# KeyboardState.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Input.KeyboardState
的用法示例。
在下文中一共展示了KeyboardState.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoKeyboardEvents
private void DoKeyboardEvents(GameTime gameTime)
{
// TODO: Put all keyboard checks in here
if (Keyboard.GetState().GetPressedKeys().Length < 1)
{
lastKeyHash = -1;
}
if (FocusedTextbox != No_Focused_Textbox)
{
if ((gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 5 && lastKeyPress.GetHashCode() != Keyboard.GetState().GetHashCode()) || (gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 1050 && lastKeyPress.GetHashCode() == Keyboard.GetState().GetHashCode()))
{
lastKeyPress = Keyboard.GetState();
Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
if (pressedKeys.Length > 0 && lastKeyHash != pressedKeys[0].GetHashCode())
{
if (pressedKeys[0] == Keys.Back)
{
string tmpText = GetTextboxByID(FocusedTextbox).Text;
if (tmpText.Length > 0)
{
GetTextboxByID(FocusedTextbox).Text = tmpText.Substring(0, tmpText.Length - 1);
}
}
/*else if(pressedKeys[i] == Keys.Space)
{
GetTextboxByID(FocusedTextbox).Text += " ";
}*/
else
{
if (GetTextboxByID(FocusedTextbox).Text.Length < GetTextboxByID(FocusedTextbox).MaxChars)
{
if ((pressedKeys[0].GetHashCode() > 95 && pressedKeys[0].GetHashCode() < 106))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(6);
}
else if ((pressedKeys[0].GetHashCode() > 47 && pressedKeys[0].GetHashCode() < 58))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(1);
}
}
lastKeyHash = pressedKeys[0].GetHashCode();
}
TimeOfLastKeyPress = (int)gameTime.TotalGameTime.TotalMilliseconds;
}
}
else if (gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 450 && lastKeyPress.GetHashCode() == Keyboard.GetState().GetHashCode())
{
lastKeyPress = Keyboard.GetState();
Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
if (pressedKeys.Length > 0)
{
if (pressedKeys[0] == Keys.Back)
{
string tmpText = GetTextboxByID(FocusedTextbox).Text;
if (tmpText.Length > 0)
{
GetTextboxByID(FocusedTextbox).Text = tmpText.Substring(0, tmpText.Length - 1);
}
}
//else if(pressedKeys[i] == Keys.Space)
//{
// GetTextboxByID(FocusedTextbox).Text += " ";
//}
else
{
if (GetTextboxByID(FocusedTextbox).Text.Length < GetTextboxByID(FocusedTextbox).MaxChars)
{
if ((pressedKeys[0].GetHashCode() > 95 && pressedKeys[0].GetHashCode() < 106))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(6);
}
else if ((pressedKeys[0].GetHashCode() > 47 && pressedKeys[0].GetHashCode() < 58))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(1);
}
}
}
lastKeyHash = pressedKeys[0].GetHashCode();
}
if (lastKeyPress.GetHashCode() != Keyboard.GetState().GetHashCode())
TimeOfLastKeyPress = (int)gameTime.TotalGameTime.TotalMilliseconds;
}
}
if (gameTime.TotalGameTime.TotalMilliseconds - TimeOfLastMovement > 250)
{
if (this.IsActive)
{
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
if (!OutOfBoundaries(new Coordinates(CurrentPosition.X + 1, CurrentPosition.Y)))
{
CurrentPosition = new Coordinates(CurrentPosition.X + 1, CurrentPosition.Y);
TimeOfLastMovement = (int)gameTime.TotalGameTime.TotalMilliseconds;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
//.........这里部分代码省略.........
示例2: Keyboard_Chat
private void Keyboard_Chat(GameTime gameTime)
{
if (!lastKeyPress.IsKeyDown(Keys.CapsLock) && Keyboard.GetState().IsKeyDown(Keys.CapsLock))
{
CapsLocked = !CapsLocked;
lastKeyPress = Keyboard.GetState();
}
if (FocusedTextbox != No_Focused_Textbox)
{
if ((gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress && lastKeyPress.GetHashCode() != Keyboard.GetState().GetHashCode()) || (gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 1050 && lastKeyPress.GetHashCode() == Keyboard.GetState().GetHashCode()))
{
lastKeyPress = Keyboard.GetState();
Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
if (pressedKeys.Length > 0 && lastKeyHash != pressedKeys[0].GetHashCode())
{
if (pressedKeys[0] == Keys.Back)
{
string tmpText = GetTextboxByID(FocusedTextbox).Text;
if (tmpText.Length > 0)
{
GetTextboxByID(FocusedTextbox).Text = tmpText.Substring(0, tmpText.Length - 1);
}
}
else if (pressedKeys[0] == Keys.Space)
{
if ((gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 100))
GetTextboxByID(FocusedTextbox).Text += " ";
}
else
{
if (GetTextboxByID(FocusedTextbox).Text.Length < GetTextboxByID(FocusedTextbox).MaxChars)
{
if ((pressedKeys[0].GetHashCode() > 95 && pressedKeys[0].GetHashCode() < 106))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(6);
}
else if ((pressedKeys[0].GetHashCode() > 47 && pressedKeys[0].GetHashCode() < 58))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(1);
}
else if ((pressedKeys[0].GetHashCode() > 64 && pressedKeys[0].GetHashCode() < 91))
{
if (lastKeyPress.IsKeyDown(Keys.LeftShift) || lastKeyPress.IsKeyDown(Keys.RightShift) || CapsLocked)
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString();
}
else
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().ToLower();
}
}
}
lastKeyHash = pressedKeys[0].GetHashCode();
}
TimeOfLastKeyPress = (int)gameTime.TotalGameTime.TotalMilliseconds;
}
}
else if (gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 450 && lastKeyPress.GetHashCode() == Keyboard.GetState().GetHashCode())
{
lastKeyPress = Keyboard.GetState();
Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
if (pressedKeys.Length > 0)
{
if (pressedKeys[0] == Keys.Back)
{
string tmpText = GetTextboxByID(FocusedTextbox).Text;
if (tmpText.Length > 0)
{
GetTextboxByID(FocusedTextbox).Text = tmpText.Substring(0, tmpText.Length - 1);
}
}
else if (pressedKeys[0] == Keys.Space)
{
GetTextboxByID(FocusedTextbox).Text += " ";
}
else
{
if (GetTextboxByID(FocusedTextbox).Text.Length < GetTextboxByID(FocusedTextbox).MaxChars)
{
if ((pressedKeys[0].GetHashCode() > 95 && pressedKeys[0].GetHashCode() < 106))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(6);
}
else if ((pressedKeys[0].GetHashCode() > 47 && pressedKeys[0].GetHashCode() < 58))
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(1);
}
else if ((pressedKeys[0].GetHashCode() > 64 && pressedKeys[0].GetHashCode() < 91))
{
if (lastKeyPress.IsKeyDown(Keys.LeftShift) || lastKeyPress.IsKeyDown(Keys.RightShift) || CapsLocked)
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString();
}
else
{
GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().ToLower();
}
}
}
//.........这里部分代码省略.........