虚拟点击

时间:2013-06-27 14:42:31

标签: vb.net

如何使程序根据x和y坐标点击某个位置,我告诉它点击?现在我有:mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 1)

但是当它执行时,它会点击我的鼠标所在的位置,无论我传入的x和y坐标是什么。

以下是确切的代码:

For n = 0 To dt2.Rows.Count - 1

        command = dt2.Rows(n)("Command")
        pos = dt2.Rows(n)("Position")
        x = Mid(pos, 21, 4)
        y = Mid(pos, 28, 3)

        Try

            If command = "" Then

            End If

            If command = "Double Click" Then
                mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 1)
                mouse_event(MOUSEEVENTF_RIGHTUP, x, y, 0, 1)

            End If

            If command = "Left Click" Then
                mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 1)

            End If

            If command = "Right Click" Then
                mouse_event(MOUSEEVENTF_RIGHTDOWN, x, y, 0, 1)

            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    Next

dt2是一个数据表

1 个答案:

答案 0 :(得分:1)

您需要先调用mouse_event移至(x,y),然后再次调用以点击。或者设置MOUSEEVENTF_MOVE标志以及鼠标上/下标志。

See here - 您可以在一次通话中组合多个标志或拨打多个电话。