【问题标题】:Why can't I simulate a right click here? (with Python)为什么我不能在这里模拟右键单击? (使用 Python)
【发布时间】:2018-02-03 01:55:30
【问题描述】:

我对编程很陌生,所以如果这有一个明显的答案,请原谅我,并且你知道我试图编写一个程序来执行游戏泰拉瑞亚中的钓鱼故障。 在我的代码 [主程序] 的最后一点中,我使用了函数 gui.rightClick()。该功能本身有效,但在游戏中无效。我还使用鼠标库尝试了它,我使用了函数 mouse.right_click() 并得到了相同的结果,所以我认为它必须与游戏有关。有人可以告诉我为什么会这样,是否有办法解决这个问题?这真的会帮助我,所以提前谢谢!!! :D 哦,如果你知道如何改进我的代码,请继续告诉我。再次感谢。

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)

更多信息: 我无法在泰拉瑞亚中使用这两个库模拟任何类型的鼠标点击,但可以使用 SpeedAutoClicker 程序(但这并没有真正的帮助)

【问题讨论】:

    标签: python python-3.x mouseevent right-click


    【解决方案1】:

    好吧,我发现了。右键只是为了快速让游戏识别。 我必须使用诸如 mouseUp() 和 mouseDown() 之类的东西....毕竟这是一个简单的解决方案! :D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-06
      • 2023-03-29
      • 1970-01-01
      • 2018-06-19
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多