From 9f02b6f8b8074d9a42f45013691995c5a344b855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Archer=20=E3=82=BF=E3=83=84?= Date: Thu, 15 Sep 2022 23:56:12 +0800 Subject: [PATCH 1/2] change windows api for mouse control --- FGO-py/fgoWindows.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FGO-py/fgoWindows.py b/FGO-py/fgoWindows.py index 44928c61..637124bc 100644 --- a/FGO-py/fgoWindows.py +++ b/FGO-py/fgoWindows.py @@ -61,8 +61,8 @@ def screenshot(self): return cv2.resize(result.reshape(self.height,self.width,4)[slice(self.border[1],-self.border[1])if self.border[1]else slice(None),slice(self.border[0],-self.border[0])if self.border[0]else slice(None),:3],(1280,720),interpolation=cv2.INTER_CUBIC) def touch(self,pos): lParam=round(pos[1]/self.scale+self.border[1])<<16|round(pos[0]/self.scale+self.border[0]) - win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONDOWN,0,lParam) - win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONUP,0,lParam) + win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONDOWN,win32con.VK_LBUTTON,lParam) + win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONUP,0,lParam) def swipe(self,rect): p1,p2=[numpy.array([rect[i<<1|j]/self.scale+self.border[j]for j in range(2)])for i in range(2)] vd=p2-p1 @@ -70,19 +70,19 @@ def swipe(self,rect): vd/=.2*self.scale*lvd vx=numpy.array([0.,0.]) def makeLParam(p):return int(p[1])<<16|int(p[0]) - win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONDOWN,0,makeLParam(p1)) + win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONDOWN,win32con.VK_LBUTTON,makeLParam(p1)) time.sleep(.01) for _ in range(2): - win32api.PostMessage(self.hWnd,win32con.WM_MOUSEMOVE,win32con.MK_LBUTTON,makeLParam(p1+vx)) + win32api.SendMessage(self.hWnd,win32con.WM_MOUSEMOVE,win32con.MK_LBUTTON,makeLParam(p1+vx)) vx+=vd time.sleep(.02) vd*=5 while numpy.linalg.norm(vx) Date: Fri, 16 Sep 2022 00:26:56 +0800 Subject: [PATCH 2/2] api modification --- FGO-py/fgoWindows.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FGO-py/fgoWindows.py b/FGO-py/fgoWindows.py index 637124bc..5bab7435 100644 --- a/FGO-py/fgoWindows.py +++ b/FGO-py/fgoWindows.py @@ -61,8 +61,8 @@ def screenshot(self): return cv2.resize(result.reshape(self.height,self.width,4)[slice(self.border[1],-self.border[1])if self.border[1]else slice(None),slice(self.border[0],-self.border[0])if self.border[0]else slice(None),:3],(1280,720),interpolation=cv2.INTER_CUBIC) def touch(self,pos): lParam=round(pos[1]/self.scale+self.border[1])<<16|round(pos[0]/self.scale+self.border[0]) - win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONDOWN,win32con.VK_LBUTTON,lParam) - win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONUP,0,lParam) + win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONDOWN,win32con.MK_LBUTTON,lParam) + win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONUP,0,lParam) def swipe(self,rect): p1,p2=[numpy.array([rect[i<<1|j]/self.scale+self.border[j]for j in range(2)])for i in range(2)] vd=p2-p1 @@ -70,19 +70,19 @@ def swipe(self,rect): vd/=.2*self.scale*lvd vx=numpy.array([0.,0.]) def makeLParam(p):return int(p[1])<<16|int(p[0]) - win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONDOWN,win32con.VK_LBUTTON,makeLParam(p1)) + win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONDOWN,win32con.MK_LBUTTON,makeLParam(p1)) time.sleep(.01) for _ in range(2): - win32api.SendMessage(self.hWnd,win32con.WM_MOUSEMOVE,win32con.MK_LBUTTON,makeLParam(p1+vx)) + win32api.PostMessage(self.hWnd,win32con.WM_MOUSEMOVE,win32con.MK_LBUTTON,makeLParam(p1+vx)) vx+=vd time.sleep(.02) vd*=5 while numpy.linalg.norm(vx)