title: How to make python script that performs a Mouse Click in Windows 10?
body: <p>I'm trying a simple python script, it clicks on a screen coordinate.</p>
  <p>I've tried with Pyautogui, pynput, pydirectinput, pywinauto... But in none of them the click is actually made, the only thing that works is to move the mouse to the coordinate.</p>
  <p>the scripts are simple, but it still doesn't work, by deduction I think it's a win10 related problem.</p>
  <p>Does anyone know how I can solve this?</p>
  <p>Do I need to install anything else, maybe a driver?</p>
  <p>Is it missing to give some kind of permission?</p>
  <p>is there a way for me to give command to the mouse hardware to make the click, instead of being a virtualized click?</p>
  <p><strong>Some of my attempts below</strong></p>
  <p><strong>OBS:</strong> In all attempts the mouse moves, but does not click.</p>
  <blockquote>
  <p>Pyautogui:</p>
  </blockquote>
  <pre><code>import pyautogui
  pyautogui.moveTo(35, 240)
  pyautogui.click() 
  </code></pre>
  <blockquote>
  <p>Pydirectinput:</p>
  </blockquote>
  <pre><code>import pyautogui
  import pydirectinput
  pydirectinput.moveTo(35, 240)
  pydirectinput.click()
  </code></pre>
  <blockquote>
  <p>pywinauto:</p>
  </blockquote>
  <pre><code>import pywinauto
  from pywinauto import Desktop, Application, mouse, findwindows
  
  pywinauto.mouse.move(coords=(160, 400))
  pywinauto.mouse.double_click(button='left', coords=(160, 400))
  </code></pre>
  <blockquote>
  <p>Direct windows click:</p>
  </blockquote>
  <pre><code>import win32api, win32con
  def click(x,y):
      win32api.SetCursorPos((x,y))
      win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
      win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
  click(10,200)
  </code></pre>
  <blockquote>
  <p>Autoclicker using pynput:</p>
  </blockquote>
  <pre><code>import time
  import threading
  from pynput.mouse import Button, Controller
  from pynput.keyboard import Listener, KeyCode
  
  
  delay = 0.001
  button = Button.left
  start_stop_key = KeyCode(char='s')
  exit_key = KeyCode(char='e')
  
  
  class ClickMouse(threading.Thread):
      def __init__(self, delay, button):
          super(ClickMouse, self).__init__()
          self.delay = delay
          self.button = button
          self.running = False
          self.program_running = True
  
      def start_clicking(self):
          self.running = True
  
      def stop_clicking(self):
          self.running = False
  
      def exit(self):
          self.stop_clicking()
          self.program_running = False
  
      def run(self):
          while self.program_running:
              while self.running:
                  mouse.click(self.button)
                  time.sleep(self.delay)
              time.sleep(0.1)
  
  
  mouse = Controller()
  click_thread = ClickMouse(delay, button)
  click_thread.start()
  
  
  def on_press(key):
      if key == start_stop_key:
          if click_thread.running:
              click_thread.stop_clicking()
          else:
              click_thread.start_clicking()
      elif key == exit_key:
          click_thread.exit()
          listener.stop()
  
  
  with Listener(on_press=on_press) as listener:
      listener.join()
  </code></pre>