Na instanci stavu jsou 3 metody:
... using Microsoft.Xna.Framework.Input; ... public class klavesnice : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; KeyboardState oldState; SoundEffect zvuk1, zvuk2, zvuk3; KeyboardState klavesy, klavesyMinule; ... protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here zvuk1 = Content.Load<SoundEffect>("1"); zvuk2 = Content.Load<SoundEffect>("4"); zvuk3 = Content.Load<SoundEffect>("alarm1"); } ... protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here KeyboardState keyState = Keyboard.GetState(); if(keyState.IsKeyDown(Keys.Left)) zvuk1.Play(1,1,-1); if(keyState.IsKeyDown(Keys.Right)) zvuk1.Play(1, 1, 1); // ošetření kláves na stisknutí var newState = Keyboard.GetState(); if (newState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down)) { // jedno stisknutí klávesy zvuk1.Play(); } if (newState.IsKeyDown(Keys.Up) && oldState.IsKeyDown(Keys.Up)) { // držení stisknuté klávesy zvuk2.Play(); } else if (!newState.IsKeyDown(Keys.Enter) && oldState.IsKeyDown(Keys.Enter)) { // uvolnění klávesy zvuk3.Play(); } oldState = newState; // jiný způsob ošetření klavesyMinule = klavesy; klavesy = Keyboard.GetState(); //způsob 1 if (klavesy.IsKeyDown(Keys.Space) && klavesyMinule.IsKeyUp(Keys.Space)) zvuk3.Play(); //způsob 2 if (NovaKlavesa(Keys.Escape)) zvuk2.Play(); base.Update(gameTime); } public bool NovaKlavesa(Keys klavesa) { return klavesy.IsKeyDown(klavesa) && klavesyMinule.IsKeyUp(klavesa); } }