简体   繁体   中英

pyautogui.click() doesn't work as expected

Actually, I have written a code where I've to lunch the application such that I've to click the on-screen keyboard using this pyautogui.click() . But it is not working on on-screen keyboard. I'll be pleased to have your precious opinion. Thanks in advance.

import os
import pyautogui as pg
import time
x= 195  
y=505
secret="secretpassword"
command = "application"
os.system(command)
pg.click(x, y)
pg.typewrite(secret)
pg.typewrite(["enter"])

If the application is already lunched this is working but i want to lunch it with os.system(command) and after that enter my password and access to the application.

Am I doing something wrong ?

os.system() will block and wait for the application to exit. This means that your click, in fact, will not execute until the opened appication closes. To verify this, you can open a (python) shell and run following code:

import os
import pyautogui
def test():
    os.system('<something simple opening a window>')
    pyautogui.typewrite("I'm in the shell again!")
test()

To run your script as you want, use os.popen , or, even better, subprocess.Popen . These will run the command without blocking.

If you do this, keep in mind your application will have startup time, so you will want to wait some time after the call as noted in the comments under your question.

I changed

os.system(command)

with

subprocess.Popen(command)

Now it's working

subprocess.Popen() is strict super-set of os.system().

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