Python Forum
i want to locate an image according to the mouse position
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i want to locate an image according to the mouse position
i want to to locate an image on screen by "Pyautogui.locateOnScreen" but i want the region depend to the mouse. for example if the mouse in position x,y so i want to locate on screen from this x,y position .
another example: this is the code for locate-onscreen in a region: region=(100,100,100,100) what i want like this region=(my mouse position, Width , height).
image to explain more :
[Image: 1IgRa.png]
this is my code
import pyautogui
import time


while 1:
    img = pyautogui.locateOnScreen('test.png',confidence=0.8,region=(280,284,261,228))
    if img:

        pyautogui.moveRel(-196, 5)
       # pyautogui.locateOnScreen(here where i want add the region who depends on the mouse position ) )

        print ('non')
img = pyautogui.locateOnScreen('test.png',confidence=0.8,region=(280,284,261,228))

I think... (280,284,261,228) represents (x, y, height, width) of the image you want. So if you use the x,y of your mouse position in there the image location will be the mouse location.

eg: (your_mouse.x - 50, your_mouse.y - 50, 100, 100) will give you a 100x100 square centered on the mouse.

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I locate in my computer, or install the file? JaneTan 1 192 Aug-26-2021, 08:37 AM
Last Post: snippsat
  Locate QR code on a page Pedroski55 0 404 Jan-21-2021, 07:11 AM
Last Post: Pedroski55
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 685 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  How to Locate an Attribute's Parent Object? calvinsomething 5 843 Nov-13-2020, 01:52 AM
Last Post: calvinsomething
  Read mouse position on separate between two HDMIs ATARI_LIVE 1 509 Sep-28-2020, 07:48 PM
  mouse position biprabu 3 673 Sep-09-2020, 08:21 PM
Last Post: deanhystad
  Move mouse and click in particular position biprabu 3 788 Sep-01-2020, 08:23 PM
Last Post: deanhystad
  mouse 0.7.0 - mouse polling hate 125-1000hz penahuse 1 886 Dec-06-2019, 09:51 PM
Last Post: Larz60+
  trying to locate a working grpc to install MrMajorThorburn 6 2,583 May-10-2019, 01:19 PM
Last Post: MrMajorThorburn
  Locate user input in a string. MjBaca 3 1,653 Apr-23-2018, 06:55 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020