Código:
Private Declare Function ClipCursor Lib "user32" (zone As RECT) As Boolean
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub main()
Dim zone As RECT
zone.Left = (Screen.Width / 2) / Screen.TwipsPerPixelX
zone.Top = (Screen.Height / 2) / Screen.TwipsPerPixelY
zone.Right = ((Screen.Width / 2) + 100) / Screen.TwipsPerPixelY
zone.Bottom = ((Screen.Height / 2) + 100) / Screen.TwipsPerPixelY
a = ClipCursor(zone)
End Sub
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub main()
Dim zone As RECT
zone.Left = (Screen.Width / 2) / Screen.TwipsPerPixelX
zone.Top = (Screen.Height / 2) / Screen.TwipsPerPixelY
zone.Right = ((Screen.Width / 2) + 100) / Screen.TwipsPerPixelY
zone.Bottom = ((Screen.Height / 2) + 100) / Screen.TwipsPerPixelY
a = ClipCursor(zone)
End Sub
Este código bloquea el ratón en el centro de la pantalla y lo deja mover unos pocos píxeles. Si se pulsa Ctrl+Alt+Supr o la tecla de Windows el ClipCursor desaparece. Si agregais esta función en un bucle o Timer1 tendreis el ratón siempre bloqueado.
Otra manera más graciosa es con la API: GetCursorPos y SetCursorPos. Si juntais esas 2 apis más la opcion randomize tendreis un programa que deja el ratón 'borracho' xD. Crear un nuevo proyecto, solo dejar el Form1.frm, añadir un Timer1 con el interval = 100:
Código:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Timer1_Timer()
Dim pnt As POINTAPI
GetCursorPos pnt
Randomize
tmp = Int(Rnd * 4) + 1
If tmp = 1 Then
curx = pnt.X + Int(Rnd * 40)
cury = pnt.Y + Int(Rnd * 40)
ElseIf tmp = 2 Then
curx = pnt.X - Int(Rnd * 40)
cury = pnt.Y - Int(Rnd * 40)
ElseIf tmp = 3 Then
curx = pnt.X + Int(Rnd * 40)
cury = pnt.Y - Int(Rnd * 40)
ElseIf tmp = 4 Then
curx = pnt.X - Int(Rnd * 40)
cury = pnt.Y + Int(Rnd * 40)
End If
SetCursorPos curx, cury
End Sub
X As Long
Y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Timer1_Timer()
Dim pnt As POINTAPI
GetCursorPos pnt
Randomize
tmp = Int(Rnd * 4) + 1
If tmp = 1 Then
curx = pnt.X + Int(Rnd * 40)
cury = pnt.Y + Int(Rnd * 40)
ElseIf tmp = 2 Then
curx = pnt.X - Int(Rnd * 40)
cury = pnt.Y - Int(Rnd * 40)
ElseIf tmp = 3 Then
curx = pnt.X + Int(Rnd * 40)
cury = pnt.Y - Int(Rnd * 40)
ElseIf tmp = 4 Then
curx = pnt.X - Int(Rnd * 40)
cury = pnt.Y + Int(Rnd * 40)
End If
SetCursorPos curx, cury
End Sub