Android S-Pen detection

Is there a way to detect whether the input comes from a touch (finger) or an S Pen? I am developing a drawing and image editing app and need to implement a ‘palm rejection’ feature, similar to what I see in other apps like Sketchbook.

I tested this on my touchscreen notebook and I’m guessing it works the same way on Android.

Inside func _input(event: InputEvent) -> void: check the type of the event.

Stylus event:
InputEventMouseMotion with pressure > 0

Touch event:
InputEventScreenTouch
InputEventScreenDrag with pressure == 0

Thank you! I saw the MouseMotion function, but I didn’t realize it was the same one for pen.