1

I have a script that strip-mines in MineCraft and occasionally places a torch at its feet. I am using PyAutoGUI to move the mouse from in front of the player to below the player, place a torch, move it back and continue mining. The problem is that it won't move the mouse down unless it is already moving (e.g. if I am wiggling the mouse a bit, then it will work). Otherwise, it just stays still.

Code (I have commented the bits that aren't to do with placing a torch):

def mine():
    count = 0
    while not found_diamonds:
        # if keyboard.is_pressed('q'):
            # break
        # pyautogui.keyDown('w')
        # pyautogui.mouseDown()
        count += 1
        if count >= 20:
            count = 0
            pyautogui.mouseUp()
            es.wait(0.01)
            pyautogui.moveRel(00, 500)
            es.wait(0.01)
            pyautogui.rightClick()
            es.wait(0.01)
            pyautogui.moveRel(00, -400)
            time.sleep(0.01)

Thanks in advance.

  • 3
    I, too, struggled with a similar problem - the main issue that I has is that MC seems to take a completely different mouse input to the ones pyautogui has to offfer - I might be wrong on that. Anyway, see: https://stackoverflow.com/questions/50712139/how-to-control-the-mouse-in-minecraft-using-python - it also talks about pynput – Larry the Llama Nov 23 '21 at 20:02
  • Like this you're mining for 0 seconds. A – Nearoo Nov 24 '21 at 10:01
  • @LarrytheLlama I had a look at that, and they seem to mention turning raw input off. I couldn't find this setting in the game anywhere, but I went into the options.txt and disabled it from there. It did help with other minor input problems, but it will still only move the mouse if it is already moving. :( – TotallyNotTeo Nov 24 '21 at 10:38
  • @Nearoo I thought that too but it works somehow. The mouse movements are still broken though – TotallyNotTeo Nov 24 '21 at 10:38
  • I'd solve that first, i.e. why it works anyway. It might mot be why you think, and the problem is elsewhere – Nearoo Nov 24 '21 at 14:02
  • This may sound silly, but is the screen actually in focus to begin with? That might be why it only works after you move it. – Larry the Llama Nov 24 '21 at 20:30
  • Try using the pydirectinput module: it's pyautogui but it works in minecraft for me. – Codeman Dec 03 '21 at 14:16

1 Answers1

0

I'm a beginner, but I had the same problem in minecraft, my mouse wouldn't move. I just had to go to minecraft > options > controls > mouse settings > toggle Raw Input to OFF

Since then it work for me, hope it can help someone else.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – xlmaster Feb 26 '23 at 12:51