From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-21-2019 10:27 AM
When my vi starts running, I would like to detect if a keyboard is connected to my computer. I can't be the only one, but after a lot of searching I could find nothing. Maybe I'm just dumb and everyone else knows how to do this... If some smarter person would be kind enough to enlighten me, I would greatly appreciate it!
Solved! Go to Solution.
01-21-2019 11:05 AM - edited 01-21-2019 11:05 AM
There is a primitive that *may* work under Connectivity -> Input Device Control -> Query Input Devices. Unfortunately, it only seems to detect my laptop's built-in keyboard, not the external USB one. It may help or it may not. I did find some .NET stuff that seems like it'll work. I gave it a few minutes but couldn't get it working, but I think I'm close. I'm no .NET guy, so I'm stumbling a bit with syntax, which I think is my main problem. Some further reading- be sure to post a solution when you find it 🙂
How to do it with .net:
How to use .NET in LV:
https://forums.ni.com/t5/Developer-Center-Resources/Calling-NET-Assemblies-from-LabVIEW/ta-p/3523180
https://forums.ni.com/t5/LabVIEW/How-to-access-WMI-Classes-via-NET-in-LabVIEW/td-p/253845
Some combination of those links should get you where you need to go.
01-21-2019 01:13 PM
Thanks, Bert! You pointed me right to the solution. I'm not a .net guy either, but I've worked with it a little bit through LabView.
I had tried the Connectivity -> Input Device Control -> Query Input Devices route; I have a Logitech mouse and keyboard with their Unifying receiver. The Query Input Devices block tells me that I have one mouse and one keyboard, not matter if I add extra keyboards or remove the keyboard; so I deemed it not reliable. The .NET function you identified did the trick. I wrote a .vi to output the count of the keyboards (or mice) that I have attached. The count is not necessarily correct; with just a USB keyboard it correctly reports "1," bit with my wireless keyboard it reports "3." With both connected it reports "4." But, with them both disconnected it correctly reports "0," which is what I need.
01-21-2019 01:28 PM
This should detect USB keyboards.
01-21-2019 02:03 PM - edited 01-21-2019 02:04 PM
Hi Paul,
When I tried running it I got an error:
01-22-2019 03:59 AM - edited 01-22-2019 04:00 AM
@JohnEE wrote:
Hi Paul,
When I tried running it I got an error:
The error handling is a bit limited and the code simply enumerates all PNP devices and tries to read its Service property which not all PNP devices have. And if one of them doesn't have such a property, which is very common on not so new Windows installations, you get this error.
When I run this code I get 174 device records as result, which all are checked for that property and about half of them don't have it.