0
我想檢查一個鍵是否與Xna.Framwork.Input鍵盤上按下,但我使用的方法不看到工作。GetState.IsKeyDown()永遠不會返回true(Microsoft.Xna.Framework.Input.Keyboard)
我的代碼(僅重要部分):
using System.Threading;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
private static void GetInput() {
for (int i = 0; i < 1000; i++) {
Update();
if (IsKeyPressed(Keys.W)) {
Console.WriteLine("W pressed");
}
if (IsKeyPressed(Keys.S)) {
Console.WriteLine("S pressed");
}
Thread.Sleep(10);
}
}
public static KeyboardState CurrentKeyboardState { get; private set; }
public static void Update() {
CurrentKeyboardState = Keyboard.GetState();
}
public static bool IsKeyPressed(Keys key) {
return CurrentKeyboardState.IsKeyDown(key);
}
不管我怎麼按, 「IsKeyPressed」 永不返回true。
該方法在一個新的線程中執行,但在主線程中運行它並沒有改變任何東西。
我使用Visual Studio 2012旗艦版更新1,.NET 4.5,Win 7的64,XNA遊戲工作室4.0
是我的代碼不正確或有問題的其他地方?