the problems i get:
Thread.Sleep(1000 / 60)
- name "Thread" is not declared
Public Shared Sub Main()
-satatement cannot appear within a method body, end og method assumed
Call New Thread(AddressOf MouseCheck).Start()
- type "thread" is not defined
Here is my code:
Public Class Form1
Private Shared _savedMousePosition As Point
Private Shared Sub MouseCheck()
'We are doing a loop here to check if the mouse has moved a certain amount of pixels
'if so then show the popup and reset the saved position.
While True
'First check if the current mouse position has a distance of 20pixels from the saved position
'we use the > operator because the distance will almost never be exactly 20Pixels (i mean 20.000000)
If DistanceBetween(_savedMousePosition, Cursor.Position) > 20 Then
MsgBox("Mouse moved 20 pixels!")
'here we reset the saved position to the current mouseposition and
'start all over again...
_savedMousePosition = Cursor.Position
End If
'we dont need a lot of checks this will only couse a high CPU usage
'so lets check the position 60 times a second
Thread.Sleep(1000 / 60)
End While
End Sub
Private Shared Function DistanceBetween(ByVal Point1 As Point, ByVal Point2 As Point) As Single
Return Math.Sqrt((Math.Abs(Point2.X - Point1.X) ^ 2) + (Math.Abs(Point2.Y - Point1.Y) ^ 2))
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Public Shared Sub Main()
'We save the current position when the app starts
'so the popup will not popup directly
_savedMousePosition = Cursor.Position
Call New Thread(AddressOf MouseCheck).Start()
Process.GetCurrentProcess.WaitForExit()
End Sub
End Class