기술/beginning games2011.05.24 18:38
download download
public class KeyTest extends Activity implements OnKeyListener{

StringBuilder b = new StringBuilder();
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   textView = new TextView(this);
   textView.setText("키 입력");
   textView.setOnKeyListener(this);
   textView.setFocusableInTouchMode(true);   // 터치를 해야 키보드가 뜸
   setContentView(textView);
}

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
b.setLength(0);
switch(event.getAction()){
case KeyEvent.ACTION_DOWN:
b.append("down, ");
break;
case KeyEvent.ACTION_UP:
b.append("up, ");
break;
}
b.append(event.getKeyCode());
b.append(", ");
b.append((char)event.getUnicodeChar());
String text = b.toString();
Log.d("Key Text", text);
textView.setText(text);
if(event.getKeyCode()==KeyEvent.KEYCODE_BACK)
return false;
else
return true;
}
}
저작자 표시
신고
download download download
Posted by [lying dragon] Ed Kim