How to get rid of ghost cursors via a script?

I’m using a touchscreen device with Gnome. Now Gnome, despite its great design, is extremely buggy when it comes to touch screens, and I frequently get phantom cursors messing all my stuff up. To solve this problem I wish to write a script that will restart the Gnome shell and get rid of them.

This was easily possible on x11: killall -3 gnome-shell. On Wayland, the only way I have found is to lock the screen and log in again. This means that my fully automated script looks like this:

#!/bin/bash
loginctl lock-screen
ydotool key enter
ydotool type "my password, in plain text"
ydotool key enter

I shan’t elaborate on what a vile and horrific idea this is in terms of security, and how unhappy I am that it is my only option for complete automation.

Mind you, full automation is occasionally THE ONLY OPTION. If the touchscreen stops responding entirely as sometimes happens, my only controls left are the power button and the volume keys - my intention is to run the final script by pressing both volume keys simultaneously.

What alternatives do I have? Does anyone know of a more direct way of getting rid of ghost cursors? Is the next version of GNOME focused entirely on fixing its numerous touchscreen bugs?