简体   繁体   English

为什么我不能在这里模拟右键? (使用Python)

[英]Why can't I simulate a right click here? (with Python)

I'm very new to programing so please forgive me if this has an obvious answer and just so you know I tried to write a program that performs a fishing glitch in the game Terraria. 我是编程的新手,所以如果答案很明显,请原谅我,并且您知道我试图编写一个在Terraria游戏中执行钓鱼故障的程序。 In the last bit of my code [Main Program] I used the function gui.rightClick(). 在代码的最后一部分[主程序]中,我使用了函数gui.rightClick()。 The function itself works but not in the game. 该功能本身有效,但不适用于游戏。 I also tried it with the mouse library where I used the function mouse.right_click() and came to the same result so I figured that it has to do something with the game. 我还在使用函数mouse.right_click()的鼠标库中进行了尝试,并得到了相同的结果,因此我发现它必须与游戏有关。 Can someone tell me why that is and if there is a way around that? 有人可以告诉我为什么吗,是否可以解决? It would really help me so thanks in advance!!! 这真的会对我有帮助,所以在此先感谢!!! :D Oh and if you know how to improve my code please go right ahead and tell me. :D哦,如果您知道如何改进我的代码,请继续告诉我。 Thanks again. 再次感谢。

import pyautogui as gui
import keyboard, _thread, sys, time

# Global variable for shutting down the program
shutDown = False

# Position of disposable stuff in the inventory
item_x, item_y = 279, 233

# Function that tells the main thread to shut down
def pClose():
    global shutDown
    while True:
        try:
            if keyboard.is_pressed("alt+c"):
                shutDown = True
                sys.exit()
        except:
            continue

# Function that checks if it's supposed to shut down the main thread
def pQuit(sD):
    if sD == True:
        sys.exit()

# Initializing thread with pClose()
_thread.start_new_thread(pClose,())

# Start Position of the Cursor
while True:
    try:
        if keyboard.is_pressed("alt+p"):
            start_x, start_y = gui.position()
            break
    except:
        continue

time.sleep(2)

# Main Program
for i in range(10):
    pQuit(shutDown)
    gui.press("e")
    pQuit(shutDown)
    gui.moveTo(item_x, item_y, duration= 0.25)
    pQuit(shutDown)
    gui.rightClick()
    pQuit(shutDown)
    gui.moveTo(start_x, start_y, duration= 0.25)
    pQuit(shutDown)
    gui.rightClick()
    pQuit(shutDown)
    gui.press("e")
    pQuit(shutDown)
    time.sleep(0.5)

More Info: I can't simulate any kind of mouse click with these two libraries in Terraria but with the program SpeedAutoClicker it does (but that's no really helpful) 更多信息:我无法使用Terraria中的这两个库模拟任何类型的鼠标单击,但是可以使用SpeedAutoClicker程序进行模拟(但这并没有真正的帮助)

Okey I found out. 我发现了。 The right click is just to fast for the game to recognize. 右键单击只是为了让游戏快速识别。 I have to use something like mouseUp() and mouseDown().... Well it was a simple solution after all! 我必须使用诸如mouseUp()和mouseDown()之类的东西……毕竟这是一个简单的解决方案! :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM