Controlling mouse movement with python inside a game
Controlling mouse movement with python inside a game
I want to learn some reinforcement-learning concepts by letting my agent play a video game. In order to do so, I would like to control the mouse movement inside the game.
I've been fiddling with win32api, using win32api.SetCursorPos((x,y))
to move the mouse. While this works perfectly on my desktop, I can't find a way to translate the movement inside the game.
win32api.SetCursorPos((x,y))
I have also tried using pyautogui with no luck either.
Any suggestions on how to solve this?
1 Answer
1
from pynput.mouse import Controller, Button
def clickAt(Mouse, x, y):
Mouse.position = (x, y)
Mouse.press(Button.right)
Mouse.release(Button.right)
Mouse = Controller()
clickAt(Mouse,100,100)
This is how you do it with pynput
Put the game in windowed mode rather than full screen.
– vividpk21
Aug 29 at 21:34
I did, but once I click on the game window the mouse "disappears". It recognizes mouse clicks but not the movement
– AaronDT
Aug 29 at 21:35
That's a different question all together, you need to figure out what library/how the game itself is handling input and then find a way to simulate so that it behaves as you want.
– vividpk21
Aug 30 at 4:25
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
same problem as with the other modules I've tried. It works on desktop but not ingame :S
– AaronDT
Aug 29 at 21:33