SetCursorPos是设置光标而不是鼠标。
使用mouse_event 移动鼠标到指定位置。
以下代码供参考:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_MOVE =1 '移动鼠标标志
Private Const MOUSEEVENTF_ABSOLUTE =32768 '使用绝对坐标
Private sub command1
mouse_event MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE ,Val(Text1.Text), Val(Text2.Text),0,0
mouse_event MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_LEFTUP , 0, 0, 0, 0
end sub
Private sub command2
msgbox"模拟鼠标按键"
end sub
使用mouse_event 移动鼠标到指定位置。
以下代码供参考:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_MOVE =1 '移动鼠标标志
Private Const MOUSEEVENTF_ABSOLUTE =32768 '使用绝对坐标
Private sub command1
mouse_event MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE ,Val(Text1.Text), Val(Text2.Text),0,0
mouse_event MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_LEFTUP , 0, 0, 0, 0
end sub
Private sub command2
msgbox"模拟鼠标按键"
end sub