我用
KeyEvent ke_c = new KeyEvent(KeyEvent.FLAG_LONG_PRESS, KeyEvent.KEYCODE_POWER);    
sendKeySync(ke_c);
不能达到效果。有没有知道方法的啊?

解决方案 »

  1.   

    http://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/KeyEvent ke_c = new KeyEvent(KeyEvent.FLAG_LONG_PRESS, KeyEvent.KEYCODE_POWER);  
    第一个参数传Action不是flag
      

  2.   

    public KeyEvent (int action, int code) Create a new key event.
    Parametersaction 
    action  Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
    code  The key code.
      

  3.   

    我尝试过分别两次发送DOWN和up的event,还是没有效果。
    downEvent =  new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POWER); 
    upEvent   =  new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_POWER); 
         
     
      

  4.   

    好像有模拟键盘输入的代码范例,但是power key可能不一样,这个如果是在kernel里修改可能简单点。如果是在andorid系统里修改,要对keyevent的流程相当熟悉才可以。
      

  5.   

    power key 和camera key 和其他的key在处理上不太一样,用模拟键盘输入的范例中的方法不起作用。