Hello everyone,

I am facing a small issue, tried a lot but couldn't find any solution:

Have a look on my code :

Code:
'Declaration
'For MouseHook
    Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort
    Private running As Boolean = True



#Region "MouseHook"
    Public Sub threadfunc()
        While running
            Dim pressed As Boolean = KeyStatus(Keys.LButton)
            If pressed = True Then
                MouseClickCounts = MouseClickCounts + 1
            End If
        End While

    End Sub

    Public Shared ReadOnly Property KeyStatus(ByVal Key As Keys) As Boolean
        Get
            If Key = Keys.LButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
                Key = Keys.RButton
                MessageBox.Show("right button pushed")
            ElseIf Key = Keys.RButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
                Key = Keys.LButton
                MessageBox.Show("Lbutton button pushed")
            End If
            Return GetAsyncKeyState(Key) And &H8000US
        End Get
    End Property

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        running = False
        't.Join()
    End Sub
#End Region
This code is detecting mouse clicks anywhere on screen, outside or inside vb.net application, but the issue is it counts thousand of mouse clicks without mouse clicks in just one second. if I add Messagebox then the mouse clicks counting is proper but on every click a message box appears. I just want to count mouse clicks anywhere on Computer.

Code:
ublic Sub threadfunc()
        While running
            Dim pressed As Boolean = KeyStatus(Keys.LButton)
            If pressed = True Then

                MouseClickCounts = MouseClickCounts + 1
                MessageBox.Show(MouseClickCounts.ToString & ", L/1 mouse button pressed")

            End If
        End While

    End Sub

Please help me to find the solution.

Thank you
Ladak