'Trying to make game detect mouse clicks using python, all the libraries failed

About 3-4 months ago, I decided to use my basic python knowledge to write a simple farming bot for an old RPG. After some struggling, I found a way to use pyautogui and run the script as an administrator to send key presses and mouse clicks to the game, even managed to bypass their tricky antibot system (used pyautogui locate on screen function and pytesseract OCR, source code below). Needless to say that adding new features and overcoming various problems associated with them has taught me a lot, much more than any book or video, and was a lot of fun.

But the server released a new update, which uses "smart guard" to block any commands not created by actual keyboard and mouse. Not giving up so easily, I've tried multiple workarounds, but unsuccessfully (I'm running Windows 10 x64 and the game uses DirectX):

  • Tried using other python modules, such as pydirectinput, pywinauto, keyboard etc.

  • Tried using AutoHotKey and its multiple ways of sending commands: send, sendevent, sendeventraw etc.

  • Compiled python and AHK scripts to prevent game detecting them.

  • Ran the game in VirtualBox and the script in the host machine, but the VM didn't receive input from the host, and the game was very laggy.

  • Even tested inputs with Windows On-Screen keyboard, which also got ignored.

  • Experimented with win32api, win32con to send mouse clicks/ key presses as "scancodes". But my knowledge is very limited in this area, so it could be just wrong.

Anyway, even though I failed to send a single click to the game from the script, this experience has taught me a lot. And I'd like to keep learning and messing around with the code, so I'd be grateful if anyone has any ideas or workarounds for this problem, but please keep my low amount of knowledge in mind when suggesting anything, thanks in advance :)



Solution 1:[1]

Sounds like a perfect problem for PyDirectInput

This should almost definitely do the job!

Solution 2:[2]

Using Arduino to create a virtual driver would do the trick.

Also MouClassInputInjection would work here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JustAnotherPyGuy
Solution 2 KendoClaw