I want my app to support keyboard shortcuts. Many devices, such as Asus Transformer
have external keyboard which has Ctrl key (available on API Level 11). I've made some code, to check if Ctrl key works in emulator:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(Build.VERSION.SDK_INT>10 &&
event.getAction()==KeyEvent.ACTION_DOWN &&
event.isCtrlPressed()){
String actionType="NONE";
final int keyCode = event.getKeyCode();
switch(keyCode){
case KeyEvent.KEYCODE_C:
actionType = "COPY";
break;
case KeyEvent.KEYCODE_V:
actionType = "PASTE";
break;
case KeyEvent.KEYCODE_X:
actionType = "CUT";
break;
case KeyEvent.KEYCODE_R:
actionType = "REFRESH";
break;
case KeyEvent.KEYCODE_A:
actionType = "SELECT ALL";
break;
}
Toast.makeText(ctx, actionType, Toast.LENGTH_SHORT).show();
return true;
}
return super.dispatchKeyEvent(event);
}
Unfortunately it doesn't work in emulator and I can't check it on real hardware.
I have two questions:
1. Would it work on device like Asus Transformer
?
2. Why Ctrl key does not work in emulator?
EDIT: I tried to find an answer or solution to my problem, but neither Google nor SO helped.