Reputation: 415
Can the Android emulator capture a key-press event of the computer (running the emulator) keyboard, such as: direction key, backspace key and enter key? If it could do that, can you tell me the key code of the implentation? Thanks a lot.
Upvotes: 2
Views: 2594
Reputation: 18670
The mapping between PC keyboard keys and devices keys is detailed here: http://developer.android.com/tools/help/emulator.html#KeyMapping
And you can respond to them using the keycodes that are listed here: http://developer.android.com/reference/android/view/KeyEvent.html
For instance:
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.i("test", "onKeyDown(" + keyCode + ", " + event +")");
return super.onKeyDown(keyCode, event);
}
}
Upvotes: 2