许多电子游戏中都喜欢放置一些冰块之类的东西,让人物在上面行走时,滑溜溜的,停也停不住。如果鼠标也变得滑溜溜的,那多有趣呀!
打开VB,让我们做这个程序去害人。
先声明作案工具,打开一个模块,写代码:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
接下来,在窗口代码的“定义”部分写上Const inertia = 0.618,定义“滑动系数”。这个数字取值在0~1之间,越大就越滑。如果觉得这个值不过瘾的话,不妨再设大一些。
然后在窗体中放置一个时钟,设Interval为50。在Form_Load事件中写上“Me.Hide”,然后双击时钟,写以下代码:
Private Sub Timer1_Timer()
Static ever As Boolean
Dim myPoint As POINTAPI
Static oldPoint As POINTAPI
GetCursorPos myPoint
If Not ever Then
oldPoint.x = myPoint.x
oldPoint.y = myPoint.y
ever = True
Exit Sub
End If
SetCursorPos myPoint.x + Fix(inertia * (myPoint.x - oldPoint.x)), myPoint.y + Fix(inertia * (myPoint.y - oldPoint.y))
oldPoint.x = myPoint.x
oldPoint.y = myPoint.y
End Sub
试试看,是不是很滑?为了更好的恶作剧,按老规矩,我提供了免安装版本。