ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2011年8月17日 星期三

Input keyevent : send key by command

open source / linux 系統的開發環境就是有這樣的好處,有test tool,也有 source code。
key event 的注入程式: input

source code 在
frameworks/base/cmds/input/src/com/android/commands/input


是一個 java 程式,要用 dalvik run 起來,所以附一個 run script:
frameworks/base/cmds/input

# Script to start "input" on the device, which has a very rudimentary # shell. # base=/system export CLASSPATH=$base/framework/input.jar exec app_process $base/bin com.android.commands.input.Input $*
使用方法看 source code:
String command = args[0]; if (command.equals("text")) { sendText(args[1]); } else if (command.equals("keyevent")) { sendKeyEvent(args[1]); } else if (command.equals("motionevent")) { System.err.println("Error: motionevent not yet supported."); return; }
支援 text 和 keyevent 。

keyevent 的話..
private void sendKeyEvent(String event) { int eventCode = Integer.parseInt(event); long now = SystemClock.uptimeMillis(); Log.i("SendKeyEvent", event); try { KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, eventCode, 0); KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP, eventCode, 0); (IWindowManager.Stub .asInterface(ServiceManager.getService("window"))) .injectKeyEvent(down, true); (IWindowManager.Stub .asInterface(ServiceManager.getService("window"))) .injectKeyEvent(up, true); } catch (RemoteException e) { Log.i("Input", "DeadOjbectException"); } }

就是把 event code 寫在後面:
#input keyevent code
.. 那 code 的 mapping 呢?

沒有留言:

標籤

網誌存檔