Home > other >  Python simulated mouse click is invalid. Be urgent!!!!!!
Python simulated mouse click is invalid. Be urgent!!!!!!

Time:10-09

Python was used to simulate the mouse click left key, in the very many methods, but all appear the same problem,
Program itself is not wrong, is running, if the target is the an icon on the desktop, you can click on success; But if it is a program window, it will only move the cursor to the target, cannot achieve click, strangely, I tried if target is a chrome browser window, can achieve click again, for what reason... ? How to solve... Have nothing to do with games against the external mechanism... I chose is not a game software, some not... How did the mouse daemon is that... Why the software can...

Code to write a lot of kinds, estimate principle is the same... Is the above issues,
Python code
The import win32api
The import win32gui
The import win32con
The import time
The import ctypes

Def click1 (x, y) : # first
Win32api. SetCursorPos ((x, y))
Win32api. Mouse_event (win32con MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
Win32api. Mouse_event (win32con MOUSEEVENTF_LEFTUP, x, y, 0, 0)

Def click2 (x, y) : # second
Ctypes. Windll. User32. SetCursorPos (x, y)
,0,0,0,0 ctypes. Windll. User32. Mouse_event (2)
,0,0,0,0 ctypes. Windll. User32. Mouse_event (4)

Def click_it (pos) : # third
Handle=win32gui. WindowFromPoint (pos)
Client_pos=win32gui. ScreenToClient (handle, pos)
TMP=win32api. MAKELONG (client_pos [0], client_pos [1])
Win32gui. SendMessage (handle, win32con. WM_ACTIVATE, win32con WA_ACTIVE, 0)
Win32gui. SendMessage (handle, win32con. WM_LBUTTONDOWN, win32con MK_LBUTTON, TMP)
Win32gui. SendMessage (handle, win32con. WM_LBUTTONUP, win32con MK_LBUTT

CodePudding user response:

Try using a simulated keyboard or other libraries

CodePudding user response:

Has been solved, thank you!
Solution: to administrator privileges to run python scripts
  • Related