简体   繁体   中英

Pyautogui cursor not working after seclect a text box and click at other object

I'm currently having trouble with pyautogui's cursor

When I execute the code, it click the text box and write text there. But after its done writitng and move to another object I aslo want it to click but the cursor didn't change, make the cursor stay text cursor and it cannot click anything after that despite the cursor moved to the object that I need to click.Pydirectinput didn't work aslo, can anybody help me? Thank you

code here:

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()

光标在这里,它保持这样,不能点击那个“兑换”按钮

If you are trying to click on Roblox, there are issues with Pyautogui clicking the mouse in Roblox but i've found a workaround for that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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