Wayland will be an interesting challenge, but I think there's still plenty of time before that happens.
If we figure out that this kind of automation is impossible on Wayland, I think it should still be possible to hook into the raw keyboard events with kbd and such, no? Requires root though.