Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Keyboard present in VB6 [closed]

Tags:

keyboard

vb6

I have a legacy VB6 project that can now run on systems without a keybord attached. In that case the program opens the MS on screen keyboard. I need to detect if a keyboard is attached or not. If there is a keyboard attached then skip opening the the on screen keyboard. At the moment it opens the on screen keyboard and the user must then close it. It is Clunky. I cannot migrate this application because it supports some legacy equipment that cannot be accessed by VB.net. Any Ideas please.

like image 403
Herman VanNiekerk Avatar asked Mar 28 '20 17:03

Herman VanNiekerk


1 Answers

Windows Management Instrumentation is one way you could go. The following code looks for keyboards with an OK status:

Private Function hasKeyboard() As Boolean
   Dim WMIService As Object
   Dim Items As Object
   Dim Item As Object

   hasKeyboard = False
   Set WMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
   Set Items = WMIService.ExecQuery("SELECT * FROM Win32_Keyboard")

   For Each Item In Items
      If InStr(1, UCase(Item.Status), "OK") > 0 Then
         hasKeyboard = True
         Exit Function
      End If
   Next
End Function
like image 100
Brian M Stafford Avatar answered Nov 18 '22 17:11

Brian M Stafford