2012-03-29 99 views
0

我正在嘗試檢測鍵盤輸入,並且如果按下方向鍵,請將播放器設置爲下一步移至所按的任何位置。我在聽使用鍵盤輸入:Keyboard event.charCode始終爲0

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); 

這是被調用的函數:

public function keyDown(event:KeyboardEvent):void 
{ 
    switch (event.charCode) 
    { 
     case 37: 
      this.nextMove = "LEFT"; 
      break; 
     case 38: 
      this.nextMove = "UP"; 
      break; 
     case 39: 
      this.nextMove = "RIGHT"; 
      break; 
     case 40: 
      this.nextMove = "DOWN"; 
      break; 
    } 

    trace(event.charCode); 
} 

事情是,charCode始終爲0。什麼是這種情況的原因?

回答