Hey, I totally feel your pain on this one!
I’ve run into that WinError 5 more times than I care to admit when messing around with automation scripts. It’s super frustrating because "Access Denied" is such a vague message. Since you’ve already tried running VS Code as admin, you're on the right track, but Windows (especially with games) is really protective of mouse and keyboard hooks to prevent cheating or malicious software.
Here are a few things that usually fix this for me:
1. Run the Terminal directly as Admin
Sometimes running VS Code as admin doesn't actually pass those permissions down to the integrated terminal correctly. Try this: Close VS Code, open your Command Prompt (CMD) or PowerShell by right-clicking it and selecting "Run as Administrator," then navigate to your folder and run the script using python your_script.py. This is often more reliable than running it through an IDE.
2. Switch to Windowed Borderless Mode
This is a big one! Most modern games run in "Exclusive Fullscreen" mode. When a game has exclusive control of the screen, it basically tells Windows to ignore any input that isn't coming directly from the hardware. If your game is in Fullscreen, try switching the video settings to Windowed or Windowed Borderless. This usually allows pynput or pyautogui to "inject" the mouse movements successfully.
3. Check your Antivirus (Windows Defender)
You mentioned the firewall, but the Real-time Protection in Windows Defender (or apps like Malwarebytes) often flags "Keyboard/Mouse Hooking" as a virus-like behavior. You might want to temporarily toggle off "Real-time protection" or add your Python folder to the "Exclusions" list in the Windows Security settings just to see if that's what's killing the process.
4. The Anti-Cheat Factor
If the game uses something like Easy Anti-Cheat (EAC) or BattlEye, they are specifically designed to block the exact type of mouse control pynput uses. If that's the case, WinError 5 is basically the anti-cheat software putting up a brick wall. There isn't an easy "fix" for that without getting banned, so just be careful if you're playing an online multiplayer game!
A quick tip: If you're still stuck, try testing the script on your desktop first (like making it click the Start button). If it works on the desktop but fails in the game, you know for sure it's the game's security or the window mode causing the block.
Good luck with the grind! Let me know if that helps or if you're still seeing that error pop up.