Python simulation of mouse input can affect real mice
C++sendinput also controls the real mouse
I have tried my best
I need to pursue higher performance. Although Python's performance is also sufficient,
it only takes a few seconds to draw this image at over 7000 fps,
the problem is that it will control the real mouse, which affects performance and low scalability.
Therefore, I wonder if there is a way to simply input mouse data to the specified software to make it respond to corresponding operations without affecting the physical mouse movement of the main system.
I have also inquired a lot about chatgpt online, and their answer is to use C++sendinput, but the result is that they all have the same ability to control the physical mouse
Do you know any other methods? If you could help me, I would greatly appreciate it!
In addition, here is the mouse drawing I implemented in Python, and I provided the code once for a better understanding:
import time
from PIL import Image,ImageDraw,ImageFont
import pyautogui
pyautogui.FAILSAFE = True
import time
from pymouse import PyMouse
import pyautogui
m = PyMouse()
pyautogui.FAILSAFE = True
def test(coor):
# Click on the coordinates of the corresponding pixels on the screen
off_X = 600
off_y = 300
for item in coor:
# print("-> ",item)
# pyautogui.click(item['start'] + off_X,item['y']+off_y)
m.click(item['start'] + off_X,item['y']+off_y,1)
pass
# Load the grayscale image and find the coordinates of the black pixels
grayscale_image = Image.open('./屏幕截图 2023-10-04 020426.png')
# Convert the image into grayscale using Pillow
grayscale_image = grayscale_image.convert('L')
grayscale_image.save('grayscale_image.png')
width, height = grayscale_image.size
print(grayscale_image)
def get_x():
f = 1
n = 0
coor_x = []
# coor_y = []
coor = []
# Get all black pixels
for y in range(height):
n = 0
for x in range(width):
pixel = grayscale_image.getpixel((x, y))
if pixel !=255 and f ==1:
f= 0
if pixel != 255:
coor_x.append(x)
# coor_y.append(y)
# Get multiple pixels on the same row but disconnected
if pixel==255 and f == 0:
if n == 0:
n = 1
obj = {
"start":coor_x[0],
"end":x,
"y":y,
"Nosw":True
}
coor.append(obj)
# coor_x.append(255)
coor_x = []
f = 1
else:
obj = {
"start":coor_x[0],
"end":x,
"y":y,
"Nosw":False
}
coor.append(obj)
# coor_x.append(255)
coor_x = []
f = 1
# 优化 Optimize pixel points
xxx = 0
ots = 1
nowLen = int(len(coor) * 0.5)
print("unOptLen -> ",len(coor))
while True:
if ots == 0 :
break
for item in coor:
xxx = xxx + 1
if xxx % 2 == 0:
coor.remove(item)
if(len(coor)< nowLen):
ots = 0
break
print('Opted Len -> ',len(coor))
return coor
coor = get_x()
time.sleep(3)
#
test(coor)
print("Done!")
Aucun commentaire:
Enregistrer un commentaire