Check If Mouse Exist

This code will tell you if a mouse is connected to the computer.

Module Code

Public Const SM_CMOUSEBUTTONS = 43

Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Form Code

Public Function CheckMouse() As Boolean
   If GetSystemMetrics(SM_CMOUSEBUTTONS) > 0 Then
      CheckMouse = True
   Else
      CheckMouse = False
   End If
End Function

Private Sub Form_Load()
    MsgBox "The check of mouse existence returned: " & CheckMouse
End Sub

Go Back