vb,窗体上一个点的坐标是 100 200,如何让 鼠标在这个位置自动点击一下,请给点完整的代码,多谢了

 我来答
风雪剑无痕
2012-06-18 · TA获得超过1253个赞
知道大有可为答主
回答量:1691
采纳率:100%
帮助的人:1674万
展开全部
'通用声明
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

'调用
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 100, 200, 0, 0
追问
谢谢回答,怎么没反应呀,调用
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 100, 200, 0, 0
是用一个 还是全有用呀,我测试了不行

我是写的代码
Private Sub Command4_Click()
mouse_event MOUSEEVENTF_LEFTDOWN, 100, 200, 0, 0
End Sub
追答
'通用声明
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
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 Type POINTAPI
x As Long
y As Long
End Type
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

'事件
Private Sub Command1_Click()
Dim P As POINTAPI
P.x = 0: P.y = 0
ScreenToClient Me.hwnd, P '将现有坐标0,0转换为本窗体的坐标

Dim mx As Integer, my As Integer
mx = 100: my = 200 '移动到窗体坐标为100,200的位置,单位为像素
SetCursorPos mx - P.x, my - P.y
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '单击一次
End Sub

Private Sub Command2_Click()
Print "ok?" '假设在100,200的位置上有一个按钮2,点到了就在窗体上输出"ok?"
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式