asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.25k forks source link

mouse movement don't work with game window? #274

Open moroclash opened 5 years ago

moroclash commented 5 years ago

I make small program to make some movement and clicks using pyautogui

while True:
            pyautogui.click()
            time.sleep(1)
            pyautogui.moveTo(300, 500)
            pyautogui.click()
            time.sleep(1)
            pyautogui.moveTo(1000, 500)
            pyautogui.click()
            time.sleep(1)
            pyautogui.moveTo(1000, 100)
            pyautogui.click()
            time.sleep(1)
            pyautogui.moveTo(300, 100)

it's work fine with main window, but don't work when focus on Game widow, so what's problem?

mikebvansickle commented 5 years ago

@moroclash I built a similar script to move around and pick up items using locateOnScreen(), however I had no issues.

The one thing i can think of is it may potentially not work if the game uses Fullscreen. I habitually use Windowed (Borderless), so that's what I ran mine in and it worked fine. If you're using Fullscreen, I'd suggest giving Windowed (Borderless) or vice versa.

Perhaps the python script in unable to access the window for some reason? That explanation seems weird and a stretch at best, but I'm pretty new to all this. Give different window approaches a shot and let us know what happens.

Cazzola01 commented 3 years ago

You have to use PyDirectInput. The PyDirectInput controls the Windows DirectX, which make so you can use it to move the mouse in-game.

matrndev commented 3 years ago

PyDirectInput doesn't work either.

DarkPrince27 commented 2 years ago

@mikebvansickle dude u have no f@cking idea how much i love you. Ive been struggling to get my locate on screen to work for the past few days and its been more than 30 hours ive spent on it. I seached forums and read documents but the locate would not work unless I had the shell open in the foreground. after trying without fullscreen it finally worked.

JustArtiom commented 1 year ago

is there any update? 😂 since 2021? for me PyDirectInput doesnt work (game: valorant)

CoffeSiberian commented 1 year ago

I had exactly the same problem, but I found this library that solved my problem https://pypi.org/project/PyAutoIt/

disabled01 commented 1 year ago

I had exactly the same problem, but I found this library that solved my problem https://pypi.org/project/PyAutoIt/

how pyautoit solve the problem of mouse movment for you ?

matrndev commented 1 year ago

I used AHK. Python wrapper: https://pypi.org/project/ahk/

ShadowCooper commented 3 months ago

I had exactly the same problem, but I found this library that solved my problem https://pypi.org/project/PyAutoIt/

how pyautoit solve the problem of mouse movment for you ?

The documentation is bad as it doesn't even give a list of features or a tutorial or anything (unless I'm missing something), but looking at the source code there's a mouse_move() function that worked for me (tried pyautogui and pydirectinput and they both didn't work).

I used AHK. Python wrapper: https://pypi.org/project/ahk/

Wow, didn't even know this existed, I've been using so many different libraries to automate something lol.. thanks for putting this here, it looks awesome