开发者

Is there a way to programmatically check if a Mac or PC keyboard is attached?

开发者 https://www.devze.com 2023-04-01 21:29 出处:网络
Is there a way to reliably check programmatically if the keyboard attached to a computer is a Mac keyboard with Command (⌘) and option keys, or a PC keyboard with Windows, Alt, and Menu keys? For sim

Is there a way to reliably check programmatically if the keyboard attached to a computer is a Mac keyboard with Command (⌘) and option keys, or a PC keyboard with Windows, Alt, and Menu keys? For simplicity's sake assume that there is only one keyboard attached to the computer. An operating system independent solution would b开发者_运维问答e best if there is one, but if you have to assume an OS, assume Windows 7.


Enumerate the attached USB devices and look for a keyboard. If you find one, and it's got a vendor id of 0x05AC (Apple Inc), then it's definitely an Apple keyboard. If the vendor is something else, or if you don't find any USB keyboards (e.g, the keyboard is probably hooked up via PS2), then it's probably not an Apple keyboard.

0

精彩评论

暂无评论...
验证码 换一张
取 消