Código:
'Alguns programas precisam por algum motivo limitar
'o movimento do mouse a uma determinada área.
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Function LimitaMouse(Optional X1 As Integer, Optional Y1 As Integer, Optional X2 As Integer, Optional Y2 As Integer) As Variant
Dim retangulo As RECT
retangulo.Left = X1
retangulo.Top = Y1
retangulo.Right = X2
retangulo.Bottom = Y2
ClipCursor retangulo
End Function
'Um simples teste...
Private Sub Form_Load()
LimitaMouse 50,100, 300,200
End Sub
'No evento form_Unload, digite a seguinte Linha
Private Sub Form_Unload(Cancel As Integer)
LimitaMouse 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY Rem Volta ao estado Normal
End Sub
'Onde 50 é a posição X inicial do limite
'100 é a posição Y inicial
'300 é o X final
'200 é o Y final
'Todos os valores são determinados em Pixel
'Cuidado com as coordenadas pois poderá não ter
'mais o controle do mouse, dendo assim que usar
'o teclado para finalizar o programa.
'o teclado para finalizar o programa.