_Em viết thử xí xem , mấy đại ca thấy gì không hay thì bỏ qua nha ; em mới học C# thôi [IMG]images/smilies/dont_know.gif[/IMG]
_Tạo một class ứng dụng vào một chương trình, dùng để nhận biết key được ấn khi đang làm việc khác. Ví dụ : Class dưới đây minh họa khi chơi game thì kiểm tra xem nút được Press hay release [IMG]images/smilies/biggrin.png[/IMG]
Mã:
#region Using Statementsusing System;using System.Collections.Generic;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Audio;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.Graphics;using Microsoft.Xna.Framework.Input;using Microsoft.Xna.Framework.Storage;#endregion public class GameKeyTestClass : Microsoft.Xna.Framework.Game{ GraphicsDeviceManager graphics; ContentManager content; KeyboardState oldState; public GameKeyTestClass () { graphics = new GraphicsDeviceManager( this ); content = new ContentManager( Services ); oldState = Keyboard.GetState(); } protected override void Initialize() { base.Initialize(); } protected override void LoadGraphicsContent( bool loadAllContent ) { if (loadAllContent) { } } protected override void UnloadGraphicsContent( bool unloadAllContent ) { if (unloadAllContent == true) { content.Unload(); } } protected override void Update( GameTime gameTime ) { // Mặc định thoát game trong Xbox và Win if (GamePad.GetState( PlayerIndex.One ).Buttons.Back == ButtonState.Pressed) this.Exit(); UpdateInput(); base.Update( gameTime ); } private void UpdateInput() { KeyboardState newState = Keyboard.GetState(); // Kiểm tra xem Space có bị Press không if (newState.IsKeyDown( Keys.Space )) { // Key Space được Press } // Nếu không thì kiểm tra xem nó có Down trước đó không? // có thẻ release sau đó else if (oldState.IsKeyDown( Keys.Space )) { // Space bị Release rồi } oldState = newState; } protected override void Draw( GameTime gameTime ) { graphics.GraphicsDevice.Clear( Color.CornflowerBlue ); base.Draw( gameTime ); }}
View more random threads:
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...