如何检测 Pixelbook Pen 按钮?

Posted

技术标签:

【中文标题】如何检测 Pixelbook Pen 按钮?【英文标题】:How to detect Pixelbook Pen button? 【发布时间】:2019-03-05 03:43:03 【问题描述】:

我按照the doc here 捕捉在绘图时按下 Pixelbook 笔上的按钮,但从未抛出 TOOL_TYPE_ERASER 事件。当我尝试打印日志时,我没有看到按住和释放按钮之间的任何区别:

onTouchEvent:MotionEvent  action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=2010.4766, y[0]=778.10156, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1395185, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.527 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2009.2734, y[0]=777.6406, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=1395195, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.552 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2008.0703, y[0]=776.71484, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=9, eventTime=1395221, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.569 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2007.8867, y[0]=776.25, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=1395238, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.594 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2008.0703, y[0]=775.6953, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=7, eventTime=1395263, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.611 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2008.2578, y[0]=774.58594, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=6, eventTime=1395280, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.624 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2008.3477, y[0]=773.28906, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=5, eventTime=1395295, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:35.624 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_UP, actionButton=0, id[0]=0, x[0]=2008.3477, y[0]=773.28906, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1395297, downTime=1395185, deviceId=1, source=0x1002 
2018-09-29 16:15:42.632 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=2018.3477, y[0]=1013.64453, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1402304, downTime=1402304, deviceId=1, source=0x1002 
2018-09-29 16:15:42.643 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2018.5312, y[0]=1013.64453, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=1402312, downTime=1402304, deviceId=1, source=0x1002 
2018-09-29 16:15:42.660 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2018.1641, y[0]=1013.5508, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=6, eventTime=1402329, downTime=1402304, deviceId=1, source=0x1002 
2018-09-29 16:15:42.668 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2018.1641, y[0]=1013.46094, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1402337, downTime=1402304, deviceId=1, source=0x1002 
2018-09-29 16:15:42.669 2926-2926/com.  onTouchEvent:MotionEvent  action=ACTION_UP, actionButton=0, id[0]=0, x[0]=2018.1641, y[0]=1013.46094, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1402342, downTime=1402304, deviceId=1, source=0x1002 

我的 Chrome 操作系统版本:69.0.3497.95(正式版)(64 位)

【问题讨论】:

【参考方案1】:

Google 团队确认事件已被系统占用,应用程序无法使用当前 API 捕获该事件。

【讨论】:

以上是关于如何检测 Pixelbook Pen 按钮?的主要内容,如果未能解决你的问题,请参考以下文章

html 移动菜单切换按钮| http://codepen.io/agragregra/pen/bEbbmZ

html 具有下一个/上一个按钮的Bootstrap模态。资料来源:https://codepen.io/santiagocab1/pen/pJNQVd

如何在网站上添加播放按钮覆盖

如何自定义箭头和关闭按钮?

iOS - 如何检测哪个按钮触发了 segue,以及如何根据按钮显示其内容

UIButton:多个按钮 - 如何检测事件并找到点击了哪个按钮”