以下代码分别用于检测
- 是否为手写笔事件
- 是否为橡皮擦事件
- 是否为手写笔主按钮
- 是否为手写笔辅按钮
kotlin
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
val isStylus = event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_STYLUS
val isEraser = event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_ERASER
val isStylusPrimaryButton = event.buttonState == MotionEvent.BUTTON_STYLUS_PRIMARY
val isStylusSecondaryButton = event.buttonState == MotionEvent.BUTTON_STYLUS_SECONDARY
return super.dispatchTouchEvent(event)
}