frameworks/base/core/java/android/widget/EditText.java
import android.view.KeyEvent;
import android.util.Log;
private String mResult = "";
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if("Virtual".equalsIgnoreCase(event.getDevice().getName())) return super.dispatchKeyEventPreIme(event);
// 如果想过滤特殊输入设备,则可使用event.getDevice()中的属性过滤
// 并在非过滤条件后return super.dispatchKeyEventPreIme(event);
Log.e("event.getDevice().getName()=",event.getDevice().getName());
if (0 == event.getUnicodeChar()) return true;
// 每次按键后累计字符
if (event.getAction() == KeyEvent.ACTION_DOWN) {
mResult += (char) event.getUnicodeChar();
Log.e("event.getAction",mResult+" ");
}
// 码枪默认使用KEYCODE_ENTER作为结束标志
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
super.setText(mResult, BufferType.EDITABLE);
mResult = "";
}
return true;
}