How to generate KeyEvent for two buttons? That is, to generate a combination of two buttons, for example Alt and G.
I try the following methods, but it does not work:
public boolean dispatchKeyEvent(KeyEvent event) { Log.d("KeyEvent","event= "+event); if (event.getAction() != KeyEvent.ACTION_UP){ switch (event.getKeyCode()){ case KeyEvent.KEYCODE_F10: case KeyEvent.KEYCODE_PROG_GREEN: { new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_G | KeyEvent.KEYCODE_ALT_LEFT); return false; } case KeyEvent.KEYCODE_F9: case KeyEvent.KEYCODE_PROG_RED:{ dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_H | KeyEvent.KEYCODE_ALT_LEFT)); return false; } case KeyEvent.KEYCODE_F11: case KeyEvent.KEYCODE_PROG_YELLOW:{ simulateKey(KeyEvent.KEYCODE_ALT_LEFT & KeyEvent.KEYCODE_Y); return false; } case KeyEvent.KEYCODE_F12: case KeyEvent.KEYCODE_PROG_BLUE:{ simulateKey(KeyEvent.KEYCODE_ALT_LEFT | KeyEvent.KEYCODE_B); return false; } } return true; } return super.dispatchKeyEvent(event); } public static void simulateKey( final int KeyCode) { new Thread() { @Override public void run() { try { Instrumentation inst = new Instrumentation(); inst.sendKeyDownUpSync(KeyCode); } catch (Exception e) { Log.e("Exception", e.toString()); } } }.start(); }