I am currently working on a vector based note-taking app targeted for Windows, Linux, macOS and iOS/iPadOS.
You have 2 ways to deal with this:
1.) You treat touch gestures entirely as mouse inputs. (This is Godots default behaviour, it seems)
2.) You actually enable Touch Gestures on mobile: In Project Settings, you disable “Emulate Mouse from Touch” and “Emulate Touch from Mouse”.
This way, your events will fire as InputEventScreenDrag (instead of InputEventMouseMotion) and InputEventScreenTouch (instead of InputEventMouseButton).
(edit: Disabling these two emulation settings does not disable Mouse or Keyboard events completely, so you don’t have to do extra work to make 2 different projects, you can just check for all 4 events in the same _input() method. All it does is to disable the actual emulation, as otherwise these Touch and Drag events will “turn into” Mouse events which don’t have information like pressure)
The good thing:
- You can differentiate InputEventScreenDrag events by checking for is_nan(event.pressure) - if it’s not a number, then you have a finger. If it has a number, it’s the pencil.
- You have event.index for Touch events, even though you need to work yourself out what it is
The bad thing:
- This does not work with InputEventScreenTouch, no pressure-value here
- The deviceId remains the same for both events (=1), no matter if it’s a finger or a pencil, it will always be one. At least with Godot 4.1 to 4.2.1 so far.
So you have to keep track of how many “Touch” events you have, which can either be the pencil or the fingers and then work around that.
For example, if a drag event starts while only one touch event has started AND !is_nan(event.pressure) then we can 100% be sure that this is just the tip of the pencil.
If we have 1 touch event and receive a second one that starts (= 2 events at the same time) and THEN have 2 drag events that both come without pressure, we know 2 fingers are on the screen. Then it’s all about saving positions on touch, checking what’s actually happening on drag and build our logic that way.
I will have a fully working open source application later this year and I plan on building some sort of “App Toolkit” for Godot which provides some wrappers and basic functionality.
There is also a InputEventMagnifyGesture and a InputEventPanGesture, however these only seemed to be triggered by my Wacom Tablet on macOS and Windows, NOT on the iPad.