How to control the mouse in Minecraft using Python?

后端 未结 5 796
清酒与你
清酒与你 2021-02-06 14:11

All in all, I\'m trying to programmatically -and externally- control the Minecraft player\'s orientation.

No APIs, no Java mods to the game environment

Typical

5条回答
  •  你的背包
    2021-02-06 14:46

    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

提交回复
热议问题