在我的应用程序中,我需要知道哪个输入设备产生了触摸事件:鼠标、触摸屏、触摸板或其他设备。
event.getSource() 返回:
for mouse: 8194
for touchscreen: 4098
我做了一个输出到 logcat 类型源的方法:
void dumpSource(MotionEvent e) {
int s = e.getSource();
Log.e("LorieService", "Motion event is from sources: " +
((s&InputDevice.SOURCE_KEYBOARD)!=0?"keyboard ":"") +
((s&InputDevice.SOURCE_DPAD)!=0?"dpad ":"") +
((s&InputDevice.SOURCE_GAMEPAD)!=0?"gamepad ":"") +
((s&InputDevice.SOURCE_TOUCHSCREEN)!=0?"touchscreen ":"") +
((s&InputDevice.SOURCE_MOUSE)!=0?"mouse ":"") +
((s&InputDevice.SOURCE_STYLUS)!=0?"stylus ":"") +
((s&InputDevice.SOURCE_BLUETOOTH_STYLUS)!=0?"bt_stylus ":"") +
((s&InputDevice.SOURCE_TRACKBALL)!=0?"trackball ":"") +
((s&InputDevice.SOURCE_MOUSE_RELATIVE)!=0?"mouse_relative ":"") +
((s&InputDevice.SOURCE_TOUCHPAD)!=0?"touchpad ":"") +
((s&InputDevice.SOURCE_TOUCH_NAVIGATION)!=0?"touch_navigation ":"") +
((s&InputDevice.SOURCE_ROTARY_ENCODER)!=0?"rotary_encoder ":"") +
((s&InputDevice.SOURCE_JOYSTICK)!=0?"joystick ":"") +
((s&InputDevice.SOURCE_HDMI)!=0?"hdmi":"")
);
}
但它touchscreen mouse stylus bt_stylus同时为鼠标和触摸屏输出。
如何正确区分鼠标事件和触摸屏事件?
慕雪6442864
相关分类