vb 控制鼠标按要求移动。

例:在text1,text2中输入第一次单击的X,Y坐标值,在text3,text4中输入第二次的X,Y坐标值,两次单击时间间隔假定为两秒,然后单击按钮执行。... 例:在text1,text2中输入第一次单击的X,Y坐标值,在text3,text4中输入第二次的X,Y坐标值,两次单击时间间隔假定为两秒,然后单击按钮执行。 展开
 我来答
匿名用户
2013-12-16
展开全部
在屏幕下点击的话可以用鼠标全局键盘钩子。参考代码如下:
首先用建立一个标准Exe程序'把窗体名称,设定为frmMain'在窗体上建立一组文本框数组,名称为txtMsg'txtMsg(0) -- 显示鼠标左键按下的次数'txtMsg(1) -- 显示鼠标中键按下的次数'txtMsg(2) -- 显示鼠标右键按下的次数'txtMsg(3) -- 显示鼠标按下的总次数 '然后建立一个Module,并输入以下代码 Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32"(ByVal hHook As Long) As LongPublic Declare Function CallNextHookEx Lib "user32"(ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)Public Type MOUSEMSGS
X As Long 'x座标
Y As Long 'y座标
a As Long
b As Long
time As Long 'Window运行时间
End Type Public Const WH_MOUSE_LL = 14'-----------------------------------------
'消息
Public Const HC_ACTION = 0'鼠标消息
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_MBUTTONUP = &H208
Public Const WM_MBUTTONDBLCLK = &H209
Public Const WM_MOUSEACTIVATE = &H21
Public Const WM_MOUSEFIRST = &H200
Public Const WM_MOUSELAST = &H209
Public Const WM_MOUSEWHEEL = &H20APublic MouseMsg As MOUSEMSGS
Public lHook As Long '记录Hook的值,以便退出程序的时候销毁Hook
Public lClick As Long, mClick As Long, rClick As Long, tClick As Long '用来统计鼠标各个键的按下次数
'鼠标钩子
Public Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long)As Long If code = HC_ACTION Then
CopyMemory MouseMsg, lParam, LenB(MouseMsg) frmMain.Caption = "X=" + Str(MouseMsg.X) + " Y=" + Str(MouseMsg.Y)'在主窗口上显示鼠标的当前位置 Select Case wParam'根据不同鼠标动作进行处理,在这里只处理了鼠标按下的动作
Case WM_LBUTTONDOWN'左键按下
lClick = lClick + 1 '进行统计,并显示在住窗体的文本框上
tClick = tClick + 1
frmMain.txtMsg(0).Text = lClick
frmMain.txtMsg(3).Text = tClick
CallMouseHookProc = 0'这里把返回值设定为0,保证鼠标动作正常完成
Case WM_MBUTTONDOWN '中键按下
mClick = mClick + 1
tClick = tClick + 1
frmMain.txtMsg(1).Text = mClick
frmMain.txtMsg(3).Text = tClick
CallMouseHookProc = 0
Case WM_RBUTTONDOWN '右键按下
rClick = rClick + 1
tClick = tClick + 1
frmMain.txtMsg(2).Text = rClick
frmMain.txtMsg(3).Text = tClick
CallMouseHookProc = 0
End Select

End IfIf code <> 0 Then
CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam)'使用CallNextHookEx,来保证鼠标钩子能够被其它程序使用
End If

End Function '接下来,我们再给窗体里面添加代码 Private Sub AddHook() '安装鼠标钩子
lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0)
End Sub
Private Sub DelHook()'卸除鼠标钩子 UnhookWindowsHookEx lHook
End SubPrivate Sub Form_Load() '窗体载入的时候,安装鼠标钩子
AddHook
End SubPrivate Sub Form_Unload(Cancel As Integer)'窗体卸载的时候,卸除鼠标钩子
DelHook
End Sub
匿名用户
2013-12-16
展开全部
'读取鼠标位置
Dim p As POINTAPI
Call GetCursorPos(p)
MsgBox "当前鼠标位置为:" + vbCrLf + "X坐标:" + LTrim(Str(p.x)) + vbCrLf + "Y坐标:" + LTrim(Str(p.y))

'控制鼠标位置
SetCursorPos X, Y '分别是X坐标和Y坐标
'左键落下
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
'左键抬起
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'右键落下
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
'右键抬起
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0

要用的API如下……

Public 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)
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Public Type POINTAPI
x As Long
y As Long
End Type下回问之前先查查哦!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-12-16
展开全部
这样可以嘛
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
禚牧商斯雅
2020-04-26 · TA获得超过3706个赞
知道大有可为答主
回答量:3092
采纳率:29%
帮助的人:244万
展开全部
按照时间间隔分次执行的话可以用TImer控件来控制,你在做QQ视频攻击器??
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式