AndroidAbout touch device TOOL_TYPE_STYLUS

Here you can view the motionEvent of the stylus through the log.

 @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i(tag, "event=" + event);
        return true;
    }

    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        Log.i(tag, "G event=" + event);
        return true;
    }

When approaching the screen, call onGenericMotionEvent

When the screen is touched, onTouchEvent is called,

toolType[0]=TOOL_TYPE_STYLUS

Complete log with one click

10-14 12:25:30.040 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_ENTER, actionButton=0, id[0]=0, x[0]=2142.9934, y[0]=1068.1862, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798665, downTime=0, deviceId=7, source=0x5002 , displayId=0, eventId=16461402 }
10-14 12:25:30.067 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2146.1409, y[0]=1059.1779, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=13, eventTime=142798692, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=983447964 }
10-14 12:25:30.083 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2148.7458, y[0]=1056.4645, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=7, eventTime=142798710, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=645840300 }
10-14 12:25:30.092 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2149.6143, y[0]=1055.9219, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=142798713, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=62681315 }
10-14 12:25:30.099 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2152.1106, y[0]=1054.4023, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=5, eventTime=142798726, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=1026885681 }
10-14 12:25:30.108 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2155.041, y[0]=1053.5342, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798734, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=738838838 }
10-14 12:25:30.116 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2157.9717, y[0]=1052.9915, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798742, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=945623392 }
10-14 12:25:30.125 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2160.034, y[0]=1052.9915, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798750, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=209887185 }
10-14 12:25:30.133 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2163.1816, y[0]=1053.4255, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798759, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=372229236 }
10-14 12:25:30.141 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2165.678, y[0]=1054.0768, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798767, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=216054123 }
10-14 12:25:30.150 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2168.3914, y[0]=1054.728, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798775, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=101492618 }
10-14 12:25:30.153 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2171.756, y[0]=1054.9451, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=142798780, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=861304425 }
10-14 12:25:30.153 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_EXIT, actionButton=0, id[0]=0, x[0]=2171.756, y[0]=1054.9451, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798782, downTime=0, deviceId=7, source=0x5002, displayId= 0, eventId=866096615 }
10-14 12:25:30.155 6190 6190 I test9 : event=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=2171.756, y[0]=1054.9451, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798782, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=406230247 }
10-14 12:25:30.158 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2171.539, y[0]=1054.9451, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=142798785, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=120979047 }
10-14 12:25:30.166 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2170.3452, y[0]=1054.728, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798794, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=72378347 }
10-14 12:25:30.174 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2169.6938, y[0]=1053.9683, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798802, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=72421242 }
10-14 12:25:30.183 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2168.8257, y[0]=1053.2085, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798810, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=507279949 }
10-14 12:25:30.191 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2168.3914, y[0]=1052.7744, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798819, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=103703126 }
10-14 12:25:30.200 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2167.5232, y[0]=1052.6659, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798827, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=385426269 }
10-14 12:25:30.208 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2167.0889, y[0]=1052.2317, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798835, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=752640004 }
10-14 12:25:30.216 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2166.4377, y[0]=1052.1232, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798844, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=42588775 }
10-14 12:25:30.225 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2166.2207, y[0]=1052.1232, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798852, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=1020026684 }
10-14 12:25:30.226 6190 6190 I test9 : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2166.0037, y[0]=1052.1232, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x2000000, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798852, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=191886775 }
10-14 12:25:30.232 6190 6190 I test9 : event=MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=2166.0037, y[0]=1052.1232, toolType[0] =TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798854, downTime=142798782, deviceId=7, source=0x5002, displayId=0 , eventId=1059956846 }
10-14 12:25:30.234 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_ENTER, actionButton=0, id[0]=0, x[0]=2165.7866, y[0]=1052.3402, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798854, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=156568735 }
10-14 12:25:30.235 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2165.3523, y[0]=1052.5574, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=142798858, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=277665343 }
10-14 12:25:30.241 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2164.2668, y[0]=1054.0768, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798867, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=98280364 }
10-14 12:25:30.249 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2161.4448, y[0]=1056.4645, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798875, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=421868677 }
10-14 12:25:30.257 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2157.9717, y[0]=1059.0693, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798883, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=485500730 }
10-14 12:25:30.266 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2154.4985, y[0]=1061.3485, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798891, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=152502290 }
10-14 12:25:30.274 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2147.8774, y[0]=1063.5192, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798900, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=926486184 }
10-14 12:25:30.283 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2139.086, y[0]=1066.0155, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798908, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=338019200 }
10-14 12:25:30.291 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2128.7747, y[0]=1070.3568, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798918, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=1058054799 }
10-14 12:25:30.300 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2126.9294, y[0]=1071.9849, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=142798924, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=497747189 }
10-14 12:25:30.300 6190 6190 I test9 : G event=MotionEvent { action=ACTION_HOVER_EXIT, actionButton=0, id[0]=0, x[0]=2126.9294, y[0]=1071.9849, toolType[0 ]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798928, downTime=142798782, deviceId=7, source=0x5002, displayId= 0, eventId=588130330 }

In Android, the stylus is a special input device that can provide a more precise and detailed input method. Android provides a corresponding stylus event handling mechanism to support the use of stylus pens.

Stylus events are slightly different from touch events in that the stylus usually provides more information such as pressure, tilt angle, etc. When handling stylus events, you can use the following methods and properties:

  1. onTouchEvent(): Override the onTouchEvent() method in View or Activity to receive stylus events . You can handle stylus events based on the event type and properties.

  2. MotionEvent: Stylus events are represented using the MotionEvent class, which provides many useful methods to obtain information about stylus events. For example, use the event.getToolType() method to detect the tool type of the event, use the event.getPressure() method to obtain the touch pressure, and use event.getOrientation () method can obtain the tilt angle of the stylus, etc.

In Android, onGenericMotionEvent() is a callback method used to handle Generic Motion Events. It is a method of the View class that receives and handles common events related to input devices.

Universal input events can include events from multiple input devices such as mouse, trackball, and gamepad. These events are slightly different from touch events in that they provide richer input information, such as mouse wheel scrolling, trackball movement, gamepad joystick operations, etc.