0

I wrote a small code with python. But this part of the code doesn't work when game focused on and it doesnt respond back.

pyautogui.moveRel(-2, 4)

Also this part works when my cursor appear in menu or etc. too. But when i switched into game (when my cursor disappear and crosshair appeared) it doesn't work (doesn't matter fullscreen or else). These type of keyboard commands are in my code also but they works fine.

keyboard.is_pressed('Alt')

It's about mouse or pyautogui ?.. How can i make mouse moves correct ?

ChaTho
  • 662
  • 7
  • 10

3 Answers3

1

I tried this code below:

import win32con

import win32api

win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, int(10), int(10), 0, 0)

And it worked in game. I think it relative with win32con. Anyway i got it.

ChaTho
  • 662
  • 7
  • 10
1

I was with the same problem in linux. For me it was wayland. After switching to X, it worked. In /etc/gdm3/custom.conf uncomment the line #WaylandEnable=false.

papi3301
  • 93
  • 5
0

This is how PyAutoGui works:

0,0       X increases -->
+---------------------------+
|                           | Y increases
|                           |     |
|   1920 x 1080 screen      |     |
|                           |     V
|                           |
|                           |
+---------------------------+ 1919, 1079

So you need to write like this:

pyautogui.moveTo(100, 200)   # moves mouse to X of 100, Y of 200

or

pyautogui.moveTo(100, 200, 2)   # moves mouse to X of 100, Y of 200 over 2 seconds
  • But it works on other stuffs except games. Why doesn't work it in games? And my purpose is that moving the mouse with pixels, not coordinates. If there is an another way to do what i want, please share with me. – ChaTho Jul 31 '20 at 13:28
  • Because games are in the fullscreen resolution. Try this: `pyautogui.press('esc')` and then move mouse –  Jul 31 '20 at 13:34
  • This command doesn't work either and none(pyautogui commands) doesn't work in windowed/fullscreen mode. – ChaTho Jul 31 '20 at 13:51
  • @ChaTho Does the game require directX input? – The Laggy Tablet Aug 02 '20 at 12:27