Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change windows api for mouse control #85

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions FGO-py/fgoWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意到我先前在这里没有指定VK_LBUTTON,请问是没有指定此参数导致的错误还是PostMessage本身导致的错误?
此外,为保持上下文一致,请使用MK_LBUTTON,这个的值和VK_LBUTTON一样都是0x01

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意到我先前在这里没有指定VK_LBUTTON,请问是没有指定此参数导致的错误还是PostMessage本身导致的错误? 此外,为保持上下文一致,请使用MK_LBUTTON,这个的值和VK_LBUTTON一样都是0x01

这个我可以再确认一下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意到我先前在这里没有指定VK_LBUTTON,请问是没有指定此参数导致的错误还是PostMessage本身导致的错误? 此外,为保持上下文一致,请使用MK_LBUTTON,这个的值和VK_LBUTTON一样都是0x01

确认了一下,使用PostMessage配合正确的传参即可正常响应鼠标事件,已经改回PostMessage,并改为使用MK_LBUTTON

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
lvd=numpy.linalg.norm(vd)
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)<lvd:
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(.008)
time.sleep(.35)
win32api.PostMessage(self.hWnd,win32con.WM_LBUTTONUP,0,makeLParam(p2))
win32api.SendMessage(self.hWnd,win32con.WM_LBUTTONUP,0,makeLParam(p2))
def press(self,key):self.touch(KEYMAP[key])
def __del__(self):
self.hMemDc.DeleteDC()
Expand Down