Typical
I am trying to do the same thing, and I got mine to move the view in Minecraft (Java edition).
What worked for me was to use pynput with relative mouse commands. It also needed 'Raw Input' to be off in the Minecraft settings. [Esc -> Options... -> Controls... -> Mouse Settings... -> Raw input: OFF]
import pynput
mouse = pynput.mouse.Controller()
mouse.move(10, 10)
Also, here's the beginnings to a smooth movement of the mouse if anyone wants it:
def move_smooth(xm, ym, t):
for i in range(t):
if i < t/2:
h = i
else:
h = t - i
mouse.move(h*xm, h*ym)
time.sleep(1/60)
move_smooth(2, 2, 40)
Now, onto trying to make the keyboard work :P
Go to https://www.learncodebygaming.com/blog/pyautogui-not-working-use-directinput.
pydirectinput is basically pyautogui but it works with games, and uses newer winapi functions.
I managed to make it work with the mouse library. Instead of using mouse.move(x,y,absolute,duration)
I used mouse._os_mouse.move_to(x,y)
and mouse._os_mouse.move_relative(x,y)
. Take into account that if you want a smooth effect you'll have to implement it yourself using something like time.sleep(s)
.
I am in a similar situation to you. I was also unable to find a way to register my mouse movements in games such as minecraft.
However, I learned that you can use Java and the built-in robot library to achieve the mouse movement as desired. I don't know if you are set on python but if not it's worth checking out.
Try running python as admin and run the game in windowed mode. Pyautogui should work then.