简体   繁体   English

Android模拟器可以捕获PC键盘的按键事件吗

[英]Can Android emulator capture key-press event of PC keyboard

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? Android模拟器可以捕获计算机键盘(运行模拟器)的按键事件,例如:方向键,退格键和Enter键吗? If it could do that, can you tell me the key code of the implentation? 如果可以的话,您能告诉我请求的关键代码吗? Thanks a lot. 非常感谢。

The mapping between PC keyboard keys and devices keys is detailed here: http://developer.android.com/tools/help/emulator.html#KeyMapping 此处详细介绍了PC键盘键和设备键之间的映射: 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 您可以使用此处列出的键码对它们进行响应: 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);
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM