Android获取物理键盘KeyCode

//按键触发举动
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (event.getAction()) {
        case KeyEvent.ACTION_UP://键盘松开ACTION_UP 
        case KeyEvent.ACTION_DOWN: //键盘按下KeyEvent.ACTION_DOWN
            if (keyCode == KeyEvent.KEYCODE_BACK) {//获取物理键盘返回键
                try {
                    Intent newWindow = new Intent(Login.this, Eid.class);//跳转界面
                    startActivity(newWindow);
                } catch (Exception ex) {
                    tos.setText(ex.toString());
                    tos.show();
                }
            }
    }
    return false;
}


转载KeyCode列表:https://blog.csdn.net/feizhixuan46789/article/details/16801429
转物理键盘android处理键盘事件之物理按键:https://blog.csdn.net/qq_21813987/article/details/50675737

你可能感兴趣的:(Android获取物理键盘KeyCode)