vb 鼠标不停地抖动 要怎么写?

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:04:52
就是让程序运行后鼠标不停地抖动,频率很高的那种。让人点不中东西~
请问这样的效果用vb要怎么做的?万分感谢!
感谢一楼的朋友……不过你这是直线移动~没有抖动来得有感觉~呵呵

一楼的方法是很有用的哦,借鉴一下,可以完成你要鼠标上下左右不停抖动的感觉,只需要引用随机函数就行了

'引用随机函数,让鼠标在屏幕中抖动,可按Ctrl+Break暂停,或按Alt+F4结束

Private Declare Function SetCursorPos& Lib "user32" (ByVal x As Long, ByVal y As Long)
Private Declare Function GetCursorPos& Lib "user32" (XY As PointAPI)
Private Type PointAPI
x As Long: y As Long
End Type

Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 10 '抖动频率
End Sub

Private Sub Timer1_Timer()
Dim XY As PointAPI, foot As Integer
Call GetCursorPos(XY)
Randomize
foot = 5 '抖动幅度
XY.x = XY.x + 5 * (-1) ^ Int(1 + 2 * Rnd) '-1的乘方,左右抖动
XY.y = XY.y + 5 * (-1) ^ Int(1 + 2 * Rnd) '-1的乘方,上下抖动
SetCursorPos XY.x, XY.y
End Sub

'在窗体放一个 Timer1 控件
'注意:运行后你自己会无法控制鼠标,可按 Alt+F4 关闭运行
Private Declare Function SetCursorPos& Lib "user32" (ByVal x As Long, ByVal y As Long)