r/learnpython • • May 04 '23

Help using Python to move the mouse left and right in Overwatch

I started off trying pyautogui, which seemed to work in the menus and for selecting characters. During actual gameplay, pyautogui was not registered.

I swapped over to pydirectinput, and it was able to be picked up that the mouse was moving in gameplay. Unfortunately, it seems to move very unpredictability and leave the character looking at the sky or the floor every time, even when I am not sending any Y input whatsoever. I've also tried exclusively moving on the Y axis and that still has the camera moving around on the X axis in-game. If it helps I've mostly pydirectinput.move.

Any advice would be greatly appreciated, I just want to know if its possible to make the character do a roughly 45° turn with pydirectinput or something similar. Thanks!

ISSUE SOLVED: A helpful user in the comments recommended to use pydirectinput.moveRel(200, 0, relative=True)

This moved the camera in on the X axis without doing anything on the Y axis, so no more looking at the sky or floor!

0 Upvotes

21 comments sorted by

11

u/[deleted] May 04 '23

I would have to imagine the anti-cheat plays a part in this...

-3

u/i_haskill May 04 '23

I've been considering that actually. This seems the most likely case in my current opinion

3

u/[deleted] May 04 '23

Just a fair warning, Activision would have a valid case to sue you for this.

1

u/[deleted] Oct 02 '24

??? no what lmao dumbest thing ive heard

6

u/hugthemachines May 04 '23 edited May 21 '23

Just as a general note, I think many games, especially online games make efforts to avoid making any kind of cheat or bot so that may be the reason it is not working as you would like.

I tried to use pyautogui to just spam a button with a pause in Skyrim and nothing at all happened, as an example.

-5

u/i_haskill May 04 '23

I can get it to press buttons as well as to select things on the menu. I'm thinking their anti-cheat is focused on controlling aim and the camera to avoid aim-botting.

My project may be stuck here because of that.

4

u/Mirage2k May 04 '23 edited May 04 '23

OK, here's my advice:

Your project idea itself is not good. Two reasons:

The small reason (more like inconvenience) is Python is the wrong tool for interacting with an FPS game. The stereotype that "Python is too slow" may not be true for crunching lots of numbers anymore, thanks to numpy and generators, but FPS games require high responsiveness, which is something else.

The big reason is that Overwatch is an online game, where you interact with other people. YOU HAVE NO RIGHT(!) to make them involuntary subjects to your hobby project! Nor do you have the right (read the terms of service that you signed!) to run whatever scripts you want on servers that belong to someone else, be it Activision or Valve.

You seem like a creative person, I'm sure you can come up with a better project idea. A very simple solution is to download a classic single-player shooter, where you can do whatever you want.

-Edited

4

u/i_haskill May 04 '23

If im just using it in my own private lobbies and custom games or training mode then I dont really see the problem

2

u/Mirage2k May 04 '23

It's still on Activision's server. They have legal grounds to sue you for it, but more likely they'll just ban your account from OW or flag your IP address as suspicious. They have their own scripts running, and they run from the moment you start loading the game.

0

u/MaRf1Mm Apr 20 '24

"🤓☝ Well, actually, you can't just have fun! This is why I'm going to comment on this post with some nonsense about morals and won't help you."
My man just asked how to move a mouse, and you're here talking about rights. Leave my man in peace; if he's going to do some stupid stuff, then he'll get banned by the anti-cheat. If he's not banned, then who cares if a dude makes something in his spare time?

1

u/[deleted] May 04 '23

Any advice would be greatly appreciated, I just want to know if its possible to make the character do a roughly 45° turn with pydirectinput or something similar.

How much mouse movement is that? In pixels?

2

u/i_haskill May 04 '23

Well, I'm not too sure exactly because even small 10 pixel turns seem to make the camera freek out. I've tried:

pydirectinput.move(10, 0)

And the camera goes straight to the sky or floor. It seems to turn the X axis enough from what I can tell. I would try 10 pixels left or right for now

1

u/[deleted] May 04 '23

Well, the coordinate space starts with 0,0 in either the upper or lower left corner of the screen. So dead center would be something like 1000,500 or thereabouts (at 1920x1080 resolution.)

1

u/i_haskill May 04 '23

pydirectinput.moveTo is for moving to specific coordinates.

pydirectinout.move is for moving a specific amount of pixels from your current location

1

u/cmh_ender May 04 '23

are you using your code like this? try out dougdoug's code

if msg == "aim right":

pydirectinput.moveRel(200, 0, relative=True)

1

u/cmh_ender May 04 '23

also self post, I use this code to let Twitch chat control a game, and someone figured out that directx eats the pyautogui but the pydirectinput works.

0

u/i_haskill May 04 '23

That relative=True bit solved my problem! Thanks so much

0

u/NSNick May 04 '23

Haven't worked with pydirectinput, but maybe the flags are set such that instead of moving the mouse over 10, you're moving it to the screen coordinates of (10, 0)?

1

u/i_haskill May 04 '23 edited May 04 '23

From what I understood, it would only read it as coordinates if I used pydirectinput.moveTo

Pydirectinput.move should be for moving a specific amount of pixels only

Edit: to add onto this, I've tested .move in the menus and it does move the mouse 10 pixels in the direction of my choosing. It just freaks out when I'm actually controlling the character for some reason

0

u/ontheroadtonull May 04 '23

Have you disabled mouse acceleration in the game?

1

u/i_haskill May 04 '23

I dont see mouse acceleration in the settings. I do see "enable high precision mouse input," which did not make a difference on or off