android.view.MotionEvent的事件触发来源的问题?

Android 码拜 9年前 (2015-04-23) 1112次浏览 0个评论

我用的是绘王USB PEN TABLET,带了一支手写笔。

public boolean onTouchEvent(android.view.MotionEvent event)  {
	int iDeviceId = event.getDeviceId();
	int iSource = event.getSource();
/*
public final int getDeviceId ()
Gets the id for the device that this event came from. An id of zero indicates that the event didn""t come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn""t depend on the values.
Returns
    The device id.

public final int getSource ()
Gets the source of the event.
Returns
    The event source or SOURCE_UNKNOWN if unknown.
*/

调试的结果是:
鼠标 iDeviceId = 1;iSource = 8194;
绘王 iDeviceId = 5;iSource = 24578;
现在,在帮助文档里并未找到各种设备的常量定义。绘王这个设备难不成就用5和24578识别?

android.view.MotionEvent的事件触发来源的问题?
40分
有意思,帮忙顶一下。
android.view.MotionEvent的事件触发来源的问题?
这个输入源,确实“An id of zero indicates that the event didn””t come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn””t depend on the values.”是可变的,那如何确认是我的手写板呢?
android.view.MotionEvent的事件触发来源的问题?
测试了
     getDeviceId   和  getSource           设备源点击
一:非触摸屏显示器
1)              1         和  0x2002                  键鼠一体
2)              5         和  0x6002                  手写板
3)              1         和  0x2002                  鼠标

二:触摸屏显示器
4)              4         和  0x1002                  触摸屏显示器
5)              3         和  0x6002                  手写板

由此看来,getDeviceId 不能唯一标示设备就不知道getSource是值能否唯一标示手写板设备

android.view.MotionEvent的事件触发来源的问题?
@Override
	public boolean onTouchEvent(android.view.MotionEvent event) {
		if (mStop) {
			return true;
		}

		int iSource = event.getSource();
		int iCheck = iSource & InputDevice.SOURCE_STYLUS;
		if (iCheck != InputDevice.SOURCE_STYLUS) {
			return true;
		}

这样就可以了


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明android.view.MotionEvent的事件触发来源的问题?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!