vb如何控制鼠标移动。例如在text1、text2中分别输入x、y坐标。单击按钮然后鼠标指针移动到相应的位置

 我来答
dynamicaa
2012-05-23 · 超过14用户采纳过TA的回答
知道答主
回答量:27
采纳率:100%
帮助的人:22.6万
展开全部
Option Explicit

Private Declare Function SetCursorPos Lib "user32" ( _
ByVal x As Long, _
ByVal y As Long _
) 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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

Private Sub Command1_Click()
SetCursorPos Text1.Text , Text2.Text
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
chinaboyzyq
2012-05-23 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:3278万
展开全部
Private Declare Function SetCursorPos Lib "user32" _
(ByVal X As Long, ByVal Y As Long) As Long

Private Sub Command1_Click()
SetCursorPos Val(Text1), Val(Text2)

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友bdb9803
2012-05-23 · TA获得超过1.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:53%
帮助的人:1亿
展开全部
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Command1_Click()
Dim P As POINTAPI
P.x = Val(Text1)
P.y = Val(Text2)
SetCursorPos P.x, P.y
End Sub
追问
直接用 SetCursorPos text1.text,text2.text 不行吗??
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
通配符呢
2012-05-23 · TA获得超过121个赞
知道小有建树答主
回答量:332
采纳率:50%
帮助的人:163万
展开全部
两种方法:
1,全局都能用得上的模块.
Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Type POINTAPI
x As Long
y As Long
End Type
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long '鼠标移动位置申明.
'然后这是窗口用计时器
Private Sub Timer1_Timer()
Dim z As POINTAPI
GetCursorPos z
Text1.Text = "MouseX:" & z.x & Space(5) & "MouseY:" & z.y '鼠标位置
End Sub

2,窗口内部的XY位置
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = "MouseX:" & X & Space(5) & "MouseY:" & Y '鼠标位置
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式