2012-04-08 11 views
1

キー入力を取得する必要があります。数字の1〜9のいずれかであれば、int値を取得します。 NumPad9が押された場合例えばnumpadキー入力をint値に変換する

が、私は時間のためにそれに取り組んできた値9.

を取得する必要があり、それを解決するために見えることはできません。ここで

は、私がこれまでにやっていることです:

class Input 
{ 
    private int[] Key = { 7, 8, 9, 4, 5, 6, 1, 2, 3 }; 
    private Position[] Values; 
    public Input() 
    { 
     Values = new Position[9]; 
     int index = 0; 
     for (int i = 0; i < 3; i++) 
      for (int j = 0; j < 3; j++) 
       Values[index++] = new Position(i, j); 

    } 
    public Position GetPos(int Key) 
    { 
     return Values[Key]; 
    } 
    /*public Position ReadInput(KeyboardState Keyboard) 
    { 
    * Here is the function that I need to call, how can I check efficiently if one of the 
    * Numpads 1-9 is pressed? 
    * return GetPos(IntegerValue); 
    }*/ 
} 

位置タイプがちょうど行とコルint型の値が含まれています。

また、1つのキーだけが押されているかどうかを確認する方法はありますか?

+1

ルック](http://stackoverflow.com/questions/375316/xna-keyboard-text-input) –

答えて

1

あなたはCOLと行の値を必要とする場合、私は

bool TryReadInput(out int Value) 
{ 
    int Min = (int) Keys.D0; 
    int Max = (int) Keys.D9; 
    for (int k = Min; k<=Max; k++) 
    { 
     if (current_kb_state.IsKeyDown((Keys) k) 
      && previous_kb_state.IsKeyUp((Keys) k)) 
     { 
      value = k - Min; 
      return true; 
     } 
    } 
    value = -1; 
    return false; 
} 

...あなたが必要かわからないんだけど、これに似たものでなければなりません:この[質問で

col = (key+1)/3; 
row = (key+1) % 3; 
関連する問題