如何以编程方式检查键盘是否已连接? [英] How to check programatically if keyboard is connected or not?
本文介绍了如何以编程方式检查键盘是否已连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C#winforms开发应用程序。
I am developing an application with C# winforms.
我们的应用程序将安装在win8表面(触摸屏设备)上。
Our application is going to be installed on win8 surface(touch screen device).
我们要检查键盘是否通过USB连接,那么我们的应用程序将不会显示软键盘,否则会显示。
We want to check if a keyboard is connected via USB then our app will not show soft keypad otherwise it will show.
许多方法
请问我是否不清楚。
预先感谢。
推荐答案
我刚刚编写并在W8上进行了测试:
I just wrote this and tested on W8:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select Name from Win32_Keyboard");
foreach(ManagementObject keyboard in searcher.Get())
{
if (!keyboard.GetPropertyValue("Name").Equals(""))
{
Console.WriteLine("KB Name: {0}", keyboard.GetPropertyValue("Name"));
}
}
我还连接了第二个键盘,可以看到已检测到它。当我拔出一个插头时,我得到一个条目,而当拔出两个插头时,我却什么都没有。
I also connected a second keyboard and can see it detected. When I unplug one I get one entry, when unplug both I get nothing.
I also found some examples here: Example 1 and here Example 2
希望这会有所帮助。
这篇关于如何以编程方式检查键盘是否已连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文