You can try using mini4work/lib-io. However, please note that it is currently in development and not yet well tested.
The library utilizes PHP FFI to make low-level C calls for interacting with system-level input devices (keyboard, mouse, etc.), similar to how many Python libraries work for such purposes.