|
我用到了Canvas的keyPressed方法getGameAction监视键盘,Canvas.LEFT,Canvas.,Canvas.RIGHT,Canvas.UP,Canvas.DOWN都可以用.
但用到:Canvas.KEY_NUM0,Canvas.KEY_NUM1,...,Canvas.KEY_NUM9等数字键的时候就好象不起作用,这是怎么回事情呀?
有哪位高手指点下呀!谢谢!下面,我附上源程序:
protected synchronized void keyPressed(int keyCode) {
int action = getGameAction(keyCode);
if (action == Canvas.LEFT) { /* 左移 */
//这里上翻页
}
else if (action == Canvas.RIGHT) { /* 右移 */
//这里下翻页
}
else if (action == Canvas.UP) { /* 上移 */
if(selectedline>0){
selectedline--; //这些都正确,可以正常响应
repaint();
}
}
else if (action == Canvas.DOWN) { /* 下移 */
if(selectedline<maxLine){
selectedline++;
repaint();
}
}
else if (action == Canvas.FIRE) { /* 确定 */
//这里写选择
}
else if (action == Canvas.KEY_NUM0) {
inputstr=inputstr+"0"; //这些就不正常,不响应,就好象没操作键盘一样
repaint();
}
else if (action == Canvas.KEY_NUM1) {
inputstr=inputstr+"1";
repaint();
}
....
else if (action == Canvas.KEY_NUM9) {
inputstr=inputstr+"9";
repaint();
}
} |
|