我想通过单击 left_mouse 2 次来处理动作双击。在 2 次单击时间之间,我睡了 100 毫秒
SendInput(LEFT_CLICK...);
睡眠(100);
SendInput(LEFT_CLICK...);
它在我的 PC 上运行正常,但在虚拟机中无法正常运行 可能是,机器执行“SendInput”功能时存在延迟时间
即使我删除“Sleep(100)”,它只是单击 2 次而不是“双击“我想要的。
在这种情况下如何准确处理双击
无论如何,请建议我这样做
谢谢,
顺便说一句,您应该指定您正在使用的环境并使您的代码更加详细。使用 SendInput 是一种选择,我不知道您到底想做什么,但我会给您另外两种选择来尝试模拟点击。像这样的东西可以正常工作(我在 python 中编码,但应该是相同的想法):
def leftClick(x=0, y=0):
win32api.SetCursorPos((x,y)) #set the cursor to where you wanna click
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) #generate a mouse event
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
return True
def doubleClick(x=0, y=0):
leftClick(x,y)
leftClick(x,y)
您可以在 time.sleep(0.05) 之间睡 50 毫秒,但没有它它对我有用,而且我已经在 vm 中进行了测试。
如果您想在不移动光标的情况下执行无声单击,则可以向要单击的窗口发送消息,知道窗口句柄(hwnd),这里我假设您将句柄作为参数传递。
def leftClick(x=0, y=0, hwnd):
lParam = win32api.MAKELONG(x,y) # create a c long type to hold your click coordinates
win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lparam) # send a message to the window that the mouse left button is down.
win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lparam) # send a message to the window that the mouse left button is up.
return True
def doubleClick(x=0, y=0, hwnd):
leftClick(x,y, hwnd)
leftClick(x,y, hwnd)
或者您可以将消息WM_LBUTTONDBLCLK发送给您。