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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With