在C#中检测PS/2端口状态 [英] Detecting PS/2 port state in C#

查看:164
本文介绍了在C#中检测PS/2端口状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇文章!

我正在尝试简单地检测机器上的PS/2端口是否连接了键盘.这个想法是,计算机将启动,尽管如果它检测到USB设备或PS/2键盘,它也会重新启动进入管理员模式.

I am attempting to simply detect whether there is a keyboard attached to the PS/2 port on my machine. The idea is that the computer will boot up, although if it detects a USB device or PS/2 keyboard, it reboots into an administrator mode.

我已经处理了USB方面的问题,尽管我没有运气找到PS/2端口的任何文档.一些帖子说,引导后无法检测到插入PS/2端口的键盘,尽管我只是想检查引导时是否连接了一个键盘.

I have handled the USB aspect, although I have had no luck in finding any documentation for the PS/2 port. Some posts have said it is not possible to detect a keyboard plugged into a PS/2 port after boot, although I simply wish to check whether there is one connected at boot time.

我正在为程序使用C#,因此,尽管使用任何语言的帮助都将是有益的,但是使用该语言的任何解决方案都将非常有帮助.

I am using C# for my program and therefore any solution in this language would be very helpful, although assistance in any language would be beneficial.

非常感谢

推荐答案

WMI似乎正在这样做:

WMI seems doing it :

ConnectionOptions opts = new ConnectionOptions();
ManagementScope scope = new ManagementScope(@"\\.\root\cimv2", opts);
string query = "select * from Win32_Keyboard";
System.Management.ObjectQuery oQuery = new ObjectQuery(query);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, oQuery);
ManagementObjectCollection recordSet = searcher.Get();
foreach (ManagementObject record in recordSet)
{
    Console.WriteLine("" + record.Properties["Description"].Value);
    Console.WriteLine("" + record.Properties["Layout"].Value);
    Console.WriteLine("" + record.Properties["DeviceID"].Value);
    Console.WriteLine("" + record.Properties["PNPDeviceID"].Value);
    Console.WriteLine("" + record.Properties["Status"].Value + "\n");
}

返回:

USB人机界面设备 0000040C USB \ VID_03F0& PID_0024 \ 6& 1A939CC4& 0& 1 USB \ VID_03F0& PID_0024 \ 6& 1A939CC4& 0& 1 好

USB Human Interface Device 0000040C USB\VID_03F0&PID_0024\6&1A939CC4&0&1 USB\VID_03F0&PID_0024\6&1A939CC4&0&1 OK

标准101/102键或Microsoft Natural PS/2键盘 0000040C ACPI \ PNP0303 \ 4& 3432CBB0& 0 ACPI \ PNP0303 \ 4& 3432CBB0& 0 错误

Standard 101/102-Key or Microsoft Natural PS/2 Keyboard 0000040C ACPI\PNP0303\4&3432CBB0&0 ACPI\PNP0303\4&3432CBB0&0 Error

我没有ps/2键盘,因此状态给出了错误,但如果连接了一个,则应该具有OK状态

I don't have ps/2 keyboard so status gives error but you should have an OK status if one is connected

这篇关于在C#中检测PS/2端口状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆