LLIR: A Python Package for Recording and Replaying Raw Mouse and Keyboard Inputs

Have you ever wondered why packages like pyautogui or pynput don't work with games? They either can't send input to games altogether or the mouse input "works" but it's completely broken. Well, I created LLIR (Low-Level Input Recorder) to address these issues.

LLIR is a Python package for recording low-level mouse and keyboard events and replaying them back. It uses low-level APIs to record and playback input, making it work with many games and normal applications. The package supports Python 3.10 and later, and has been tested on Windows 10 and 11.

The main entry point to the package is the LowLevelInputRecorder class. You can import it as follows:

from llir.recorder import LowLevelInputRecorder

There are two ways to use LLIR: programmatically or using shortcuts. In either case, you need to create an instance of the LowLevelInputRecorder class.

recorder = LowLevelInputRecorder()

LLIR creates a window that's invisible and registers raw mouse and keyboard input devices to it as input sinks. This allows you to get input events even if other programs are in the foreground.

The recorded raw input is played back using the SendInput API. LLIR also attempts to replay the recorded events in exactly the same time they were recorded, with a hybrid approach of short sleeps and busy-waiting to achieve timing accuracy.

In games, this package is especially useful because it allows you to record and replay raw mouse and keyboard inputs. This means that you can obtain scan codes and mouse movement deltas, which can be sent to games in the same format they understand. The variable execution "lag" effect will be less troublesome when using LLIR with games.

LLIR is not intended as a replacement for other Python packages or dedicated automation programs like AutoHotKey. These solutions offer more functionality and convenience. However, if you need to record and replay raw mouse and keyboard inputs, LLIR can be a useful tool.

License and Release History

This package is licensed under the MIT license. You can find more information about the release history, including notifications and RSS feeds, on the project's page.

If you're interested in using LLIR, you can download the package for your platform from the project's page.