我是自动化的忠实拥护者,所以每当我有机会尝试自动化必须重复的任务时。以下代码通常允许我在屏幕上的任何位置(以及在任何可能的应用程序中)单击鼠标:
Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
这通常没有问题。我已经在一系列应用程序中使用它,效果很好。但是,我现在正在尝试对似乎完全忽略鼠标和键盘命令的应用程序进行一些鼠标单击(和击键发送)。一旦鼠标移动到程序所覆盖的屏幕区域,它就不会移动、单击等,但是我手动将鼠标移开,它会继续该过程,就好像它一直在正常工作一样。
那么有没有其他方法可以以编程方式控制鼠标,以一种与我手动移动鼠标无法区分的方式模拟鼠标?