![]() ![]() With Listener(on_click=on_click) as listener: Return False # get rid of return statement if you want a continuous loop If 0 y > 1041 and str(button) = 'Button.left' and pressed: Making a program detect if a user has clicked in a certain area (let's say, the windows 10 logo) would require another library like pynput. Location = pyautogui.locateOnScreen(win10) You also don't have to save the screenshot to a file, you can just save it as a variable import pyautogui Location = pyautogui.locateOnScreen('win10_logo.png') This following example takes a screenshot of the Windows 10 Logo, saves it to a file, and then clicks on the logo by using the specified. PyAutoGUI can also take screenshots and you can specify which region of the screen to take the shot pyautogui.screenshot(region=(0, 0, 0, 0)) The first two values are the x,y coordinates for the top left of the region you want to select, the third is how far to the right(x) and the fourth is how far down (y). The above example requires you to already have greencircle.png and all the other. Location = pyautogui.locateOnScreen(user_input + '.png') User_input = input('Where should I click?') Print('Incorrect input, available options: greencircle, redcircle, bluesquare, redtriangle') User_input = input('Where should I click? ') One way to achieve this is to take a screenshot, open it in paint and cut out only the button you want pressed (or you could have PyAutoGUI do it for you as I'll show in a later example). if you want to click on a button.png that button picture has to be the same exact size / resolution as the button in your windows for the program to recognize it. The image has to match exactly for this to work i.e. PyAutoGUI has a built in function called locateOnScreen() which returns the x, y coordinates of the center of the image if it can find it on the current screen (it takes a screenshot and then analyzes it).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |