python 选择文本框并单击其他对象后,Pyautogui光标不工作

qv7cva1a  于 2022-11-21  发布在  Python
关注(0)|答案(1)|浏览(231)

我目前在使用pyautogui的游标时遇到问题
当我执行代码时,它点击文本框并在那里写入文本。但在它完成写入并移动到另一个对象后,我也想让它点击,但光标没有改变,使光标停留在文本光标,此后它不能点击任何东西,尽管光标移动到我需要点击的对象。Pydirectinput也不工作,有人能帮助我吗?谢谢
代码:

import random as r
import pyautogui as pg
import pydirectinput as pg2
import time as t
pg.FAILSAFE = False
letter="1234567890QWERTYUIOPASDFGHJKLZXCVBNM"
generated=None
def gen():
    code=''.join(r.sample(letter,12))
    print("Generated code: ",code)
    return code
def redeem():
    pass
def check():
    pass
def mine():
    empty = pg.locateCenterOnScreen('empty.png', confidence=.9)
    redeem = pg.locateCenterOnScreen('redeem.png',confidence=.9)
    codeis = None
    ok = None
    x=None
    print(empty)
    if empty != None:
        print(empty)
        pg.moveTo(empty)
        t.sleep(0.001)
        pg2.click()
        t.sleep(0.001)
        x=gen()
        t.sleep(0.1)
        pg.write(x)
        t.sleep(.1)
        pg2.press('esc')
        if redeem != None:
            print(redeem)
            t.sleep(0.1)
            pg.moveTo(redeem)
            t.sleep(.1)
            pg2.click()
            t.sleep(0.1)
        
    else:
        pass
#main
if __name__ == '__main__':
    while True:
        mine()

bjg7j2ky

bjg7j2ky1#

如果您尝试点击Roblox,Pyautogui在Roblox中点击鼠标会出现问题,但我找到了一个解决方法:

import autoit
    if empty != None:
    print(empty)
    pg.moveTo(empty)
    t.sleep(0.001)
    autoit.mouse_click("left") #Instead of using pyautogui to click, we are gonna use autoit
    t.sleep(0.001)
    x=gen()
    t.sleep(0.1)
    pg.write(x)
    t.sleep(.1)
    pg2.press('esc')
    if redeem != None:
        print(redeem)
        t.sleep(0.1)
        pg.moveTo(redeem)
        t.sleep(.1)
        autoit.mouse_click("left") #Instead of using pyautogui to click, we are gonna use autoit
        t.sleep(0.1)
    
else:
    pass

相关问题