# Opencv python move mouse cursor rectangles

**URL:** <https://forum.opencv.org/t/opencv-python-move-mouse-cursor-rectangles/10382>\
**Category:** Python\
**Tags:** programming\
**Created:** [October 1, 2022, 5:35pm UTC](https://forum.opencv.org/t/opencv-python-move-mouse-cursor-rectangles/10382 "2022-10-01T17:35:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kokocap17](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/kokocap17/32/5598_2.png) [@kokocap17](https://forum.opencv.org/u/kokocap17)\
**Post date:** [October 1, 2022, 5:35pm UTC](https://forum.opencv.org/t/opencv-python-move-mouse-cursor-rectangles/10382/1 "2022-10-01T17:35:07Z")

</div>

I made a cascade with an opencv haar cascade , managed to scan certain objects on the screen, hover the mouse over them and click on them… But how can I move the mouse movement to the scanned thing closest to the mouse in a region that contains objects of multiple identical models. I mean this

> **[cpmeeq7.jpg](https://www.hizliresim.com/cpmeeq7)**
>
> ff

my code :

```auto
   def __init__ (self, needle_img_path):
       cv.ocl.setUseOpenCL(False)
       if needle_img_path:
           self.needle_img = cv.imread(needle_img_path)
           self.needle_w = self.needle_img.shape[1]
           self.needle_h = self.needle_img.shape[0]

   def get_click_points(self, rectangles):
       points = []
       for (x, y, w, h) in rectangles:
           center_x = x + int(w/2)
           center_y = y + int(h/2)   
           points.append((center_x, center_y))       
       return points

   def draw_rectangles(self, haystack_img, rectangles):
       line_color = (255, 255, 255)
       line_type = cv.LINE_8
       for (x, y, w, h) in rectangles:       
           top_left = (x, y)
           bottom_right = (x + w, y + h)             
           cv.rectangle(haystack_img, top_left, bottom_right, line_color, lineType=line_type)
       return haystack_img  

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 1, 2022, 6:50pm UTC](https://forum.opencv.org/t/opencv-python-move-mouse-cursor-rectangles/10382/2 "2022-10-01T18:50:33Z")

</div>

moving the mouse is beyond the scope of computer vision and OpenCV. there are libraries specifically for moving the mouse.

crosspost:

> <https://stackoverflow.com/questions/73920396/opencv-python-move-mouse-cursor-rectangles>
