我想知道在Android键盘中按下了哪个键。例如,如果a按下{a},我想在屏幕上用toast显示值{a}?
我想使用广播记录器或后台服务
答案 0 :(得分:0)
尝试在您的活动中使用dispatchKeyEvent(KeyEvent event)
:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
Log.i("key pressed", String.valueOf(event.getKeyCode()));
return super.dispatchKeyEvent(event);
}
答案 1 :(得分:0)
public class MainActivity extends Activity {
KeyEvent event;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dispatchKeyEvent(event);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
Log.i("key pressed", String.valueOf(event.getKeyCode()));
return super.dispatchKeyEvent(event);
}
}
当我运行此代码时,键盘应用程序崩溃。将显示一个包含以下信息的对话框。
不幸的是,键盘已停止