Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi 如何准确处理双击?_Winapi_Click_Double_Sendinput - Fatal编程技术网

Winapi 如何准确处理双击?

Winapi 如何准确处理双击?,winapi,click,double,sendinput,Winapi,Click,Double,Sendinput,我想通过点击鼠标左键两次来处理双击操作。在两次点击之间,我睡眠100毫秒 SendInput(左键单击…)睡眠(100)发送输入(左键单击 它在我的PC中正常工作,但在虚拟机中无法正常工作 可能是,机器执行功能“SendInput”(发送输入)时会有一段延迟时间,即使我删除“Sleep(100)”,它只会单击2次,而不会像我所希望的那样“双击” 在这种情况下,如何准确地处理双击 请无论如何建议我做这件事 谢谢,顺便说一句,您应该指定您的工作环境,并使您的代码更加详细。使用SendInput是一个

我想通过点击鼠标左键两次来处理双击操作。在两次点击之间,我睡眠100毫秒

SendInput(左键单击…)
睡眠(100)
发送输入(左键单击

它在我的PC中正常工作,但在虚拟机中无法正常工作 可能是,机器执行功能“SendInput”(发送输入)时会有一段延迟时间,即使我删除“Sleep(100)”,它只会单击2次,而不会像我所希望的那样“双击”

在这种情况下,如何准确地处理双击

请无论如何建议我做这件事


谢谢,

顺便说一句,您应该指定您的工作环境,并使您的代码更加详细。使用SendInput是一个选项,我不知道您到底想做什么,但我将为您提供另外两个用于模拟单击的选项。类似的东西可以很好地工作(我用python编写代码,但应该是相同的想法):

你可以在这段时间内睡眠50毫秒。睡眠(0.05),但如果没有它,它对我有效,我已经在虚拟机上测试过了

另一个选项是,如果希望在不移动光标的情况下执行静默单击,则可以向要单击的窗口发送一条消息,知道窗口句柄(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)

或者,您可以将消息发送给您。

副本:您应该提供代码。
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)